Friday, February 20th 2009, 5:48pm
|
|
HTML Code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title> Paging using AJAX (Google Visualization API) </title> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> google.load('visualization', '1', {packages: ['table']}); </script> <script type="text/javascript"> /** * draws the visualization, called via google.setOnLoadCallback */ function drawVisualization() { // how many items should be visible per page var limit = 4; // preload one more page var firstload_entries = (limit*2); // set the first two pages as preloaded (index is important) var cachedpages = [1,1]; // Create and populate the data table. var data = new google.visualization.DataTable(); data.addColumn('string', 'Item'); data.addColumn('number', 'Rating'); data.addColumn('boolean', 'Check'); // fill the first entries with sample data data.addRows(firstload_entries); for(var i=0; i<firstload_entries; i++) { data.setCell(i, 0, 'Item '+i); data.setCell(i, 1, i*i); data.setCell(i, 2, true); } // Create and draw the visualization. var visualization = new google.visualization.Table(document.getElementById('table')); google.visualization.events.addListener(visualization, 'page', function(e) { var next = e['page']+1; // preload next page if now existing yet if(typeof(cachedpages[next]) != 'undefined') return; // load data via json $.getJSON("status.php", {page:next, limit:limit}, function(jsondata){ // specify the index where rows should be inserted data.insertRows(next*limit, limit); // insert data $.each(jsondata, function(i,item) { for(var j=0; j<item.length; j++) { data.setCell(parseInt(i), j, item[j]); } }); // redraw the current page (activates the next button) visualization.draw(data, {page:'enable', pageSize: limit, startPage: e['page']}); // save as cached cachedpages.push(1); }); }); visualization.draw(data, {page:'enable', pageSize: limit}); } google.setOnLoadCallback(drawVisualization); </script> </head> <body style="font-family: Arial;border: 0 none;"> <h1>Paging using AJAX</h1> <h2>Google Visualization API</h2> <p>Reloads additional data and appends it to the table</p> <a href="http://www.easy-coding.de">http://www.easy-coding.de</a> <div id="table"></div> </body> </html> |