tableupdater.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. function changetable(){
  2. currPage = 0;
  3. $.post("gettable.php", {table:$("#select-table").val(), num_rows:$("#num-rows").val(), page:0}, ontabledata);
  4. }
  5. function changesort(field){
  6. if (sortParams.field == field){
  7. sortParams.dir = (sortParams.dir == ASC) ? DESC : ASC;
  8. } else {
  9. sortParams.field = field;
  10. sortParams.dir = ASC;
  11. }
  12. $.post("gettable.php", {table:$("#select-table").val(), num_rows:$("#num-rows").val(), page:currPage, order:sortParams.field, dir:sortParams.dir}, ontabledata);
  13. }
  14. function changepage(page){
  15. currPage = page - 1;
  16. $.post("gettable.php", {table:$("#select-table").val(), num_rows:$("#num-rows").val(), page:currPage, order:sortParams.field, dir:sortParams.dir}, ontabledata);
  17. }
  18. var ASC = "ASC";
  19. var DESC = "DESC";
  20. var currPage = 0;
  21. var sortParams = {field:null, dir:ASC};
  22. function ontabledata(datastr){
  23. var data = JSON.parse(datastr);
  24. var html = "<table>";
  25. html += "<thead>"
  26. html += "<tr class='title_row'>";
  27. for (var i = 0; i < data.fields.length; i++){
  28. html += "<th class='"+(((i%2)==0)?"even":"odd")+"'>";
  29. html += "<a onclick=\"changesort('"+data.fields[i]+"')\">";
  30. html += data.fields[i];
  31. if (sortParams.field == data.fields[i]){
  32. html += "<img src='assets/images/arrow_"+sortParams.dir+".png' class='"+sortParams.dir+"'/>";
  33. }
  34. html += "</a>";
  35. html += "</th>";
  36. }
  37. html += "</tr>";
  38. html += "</thead>"
  39. for (var i = 0; i < data.rows.length; i++){
  40. //
  41. html += "<tr class='"+(((i%2)==0)?"even":"odd")+"'>";
  42. for (var j = 0; j < data.rows[i].length; j++){
  43. html += "<td class='"+(((j%2)==0)?"even":"odd")+"'>"+data.rows[i][j]+"</td>";
  44. }
  45. console.log("end row");
  46. html += "</tr>";
  47. }
  48. html += "</table>";
  49. $("#table-show").html(html);
  50. var num_pages = Math.ceil(parseInt(data.total_entries)/parseInt($("#num-rows").val()));
  51. console.log("NUM PAGES:"+num_pages);
  52. if (num_pages > 0){
  53. $("#pagination").paginate({
  54. count : Math.ceil(parseInt(data.total_entries)/parseInt($("#num-rows").val())),
  55. start : currPage+1,
  56. display : 5,
  57. border : true,
  58. border_color : 'none',
  59. text_color : '#000000',
  60. background_color : 'none',
  61. border_hover_color : 'none',
  62. text_hover_color : '#000000',
  63. background_hover_color : 'none',
  64. images : true,
  65. mouse : 'press',
  66. onChange : changepage
  67. });
  68. }
  69. }