TableSorter and TableSorterPager: How to reload tablesorter table after using drop down values to run new query

TableSorter and TableSorterPager: How to reload tablesorter table after using drop down values to run new query

I have figured out how to get the page to do what they were looking for using append.

Thanks anyway...





I have taken over someones code, and most of this is very new to me.Below are the files I am working with. What is supposed to happen is that the page loads with an empty table. Then after a value, or values, are selected from the drop down, the tablesorter table should refresh based on the results from a query. Right now, the select works, the submit works, but the table does not refresh.



Javascript - including tablesorter and tablesorterPager declarations
  1. var xhr = null;
  2. var VALIDATION_URL = 'ajax.php';

  3. var campaign_summary = {
  4. table:null,
  5. body:null
  6. };

  7. var multi_list = {
  8. campaign_list: null
  9. };

  10. var campaign_array = [];

  11. function initialize(){
  12. campaign_summary.table = $('#campaignTable');
  13. campaign_summary.body = $('#campaignTable tbody');
  14. /* initialize the campaigns dropdown using the multiselectfilter widget */
  15. multi_list.campaign_list = $("#campaign_list");
  16. if( multi_list.campaign_list.length){
  17. multi_list.campaign_list.multiselect({
  18. noneSelectedText: "Select One or More Campaigns",
  19. selectedText: "# of # campaigns",
  20. minWidth: 550
  21. }).multiselectfilter();
  22. }


  23. /* get the values on submit */
  24. $("form").on("submit", function(e){
  25. e.preventDefault();
  26. campaign_array = multi_list.campaign_list.multiselect("getChecked").map(function(){
  27.     return this.value;    
  28. }).get();
  29. console.log('Campaign Array: ', campaign_array);

  30. var ajaxObj = $.ajax({
  31. url : VALIDATION_URL + '?operation=get_campaign_summary&campaign_array=' + campaign_array,
  32.             type    : $(this).attr('method'),
  33.             dataType: 'json',
  34.             data    : $(this).serialize(),
  35.             success : function( data, url ) {
  36.                         console.log('Submitted: ', data);
  37.                       },
  38.             error   : function( data, xhr, err ) {
  39.                         console.log('Oops: ', data, xhr , err);
  40.                       }
  41.         }); 
  42. console.log('ajaxObj: ', ajaxObj);
  43. return false;
  44. });

  45. /*Apply the tablesorter JQuery plugin to the summary table*/
  46. campaign_summary.table.tablesorter({
  47. theme: 'blue',
  48. widthFixed: true,
  49. sortLocaleCompare: true,
  50. widgets: ['zebra'],
  51. sortList: [ [0,1] ],
  52. headers: {
  53. '.pager' : {
  54. sorter: false
  55. },
  56. '.no_sort' : {
  57. sorter: false
  58. }
  59. }
  60. });
  61.  
  62. /*Apply the pager to the summary table, also provides AJAX calls */
  63. campaign_summary.table.tablesorterPager({
  64. container: $("#campaignTable .pager"),
  65. removeRows: false,
  66. cssGoto: '.gotoPage',
  67. ajaxUrl: VALIDATION_URL + '?operation=get_campaign_summary&page={page}&size={size}&{sortList:column}',
  68. customAjaxUrl: function(table, url) {
  69. $(table).trigger('changingUrl',url);
  70. return url;
  71. },
  72. ajaxObject: {
  73. dataType: 'json'
  74. },
  75. ajaxProcessing: function(data) {
  76. // Code to handle data recieved from database  
  77. if(!data){return;} //if nothing recieved exit
  78. total = data.total;
  79. if(total < 1){
  80. campaign_summary.body.empty();
  81. }
  82. // console.log('Data: ', data);
  83. // console.log('Data Row: ', data.rows);
  84. rows = rows_to_array(data.rows);
  85. headers = $.makeArray(data.headers);
  86. headers.push(''); //end of array
  87. return [total, rows, headers]; //Required return for pager to function
  88. }
  89. });
  90.  
  91.   /*converts the data for ticket table into an array*/
  92. function rows_to_array(rows){
  93. var ret = []
  94. for(i=0;i<rows.length;i++){
  95. ret.push(row_to_array(rows[i]));
  96. }
  97. return ret;
  98. };
  99.  
  100. /*converts one row of ticket table data into an array*/
  101. function row_to_array(row){
  102. var ret = [];
  103. ret.push(row['name']);
  104. ret.push(row['discount_rate']);
  105. ret.push(row['redeem_limit']);
  106. ret.push(row['imported_files']);
  107. ret.push(row['active_codes']);
  108. ret.push(row['future_codes']);
  109. ret.push(row['expired_codes']);
  110. ret.push(row['redeemed_codes']);
  111. ret.push(row['total_codes']);
  112. ret.push('<a href="#" onclick="update_details(&quot;' + row['id'] + '&quot;,&quot;' + row['name'] + '&quot;)">View</a>');
  113. return ret;
  114. };

  115. }

  116.   function request (options, callback) {
  117.     
  118.     // if a request has been sent out cancel it
  119.     if (xhr) {
  120.     
  121.       // IE 7 fix
  122.       try {
  123.         xhr.abort();
  124.       }
  125.       catch(e){}
  126.     }
  127.     
  128.     // send another request, store the jqXHR object
  129.     xhr = $.ajax({
  130.       type: 'GET',
  131.       url: VALIDATION_URL,
  132.       data: options,
  133.       success: function (data) {
  134.         callback(data);
  135.       },
  136.       dataType: 'json',
  137.       error: function () {
  138.       }
  139.     });
  140.     // return xhr;
  141.   }
  142.  
  143.  $(initialize)
Partial Ajax script showing get_campaign_summary call
  1. ......
  2. case 'get_campaign_summary':
  3. log_message(log_var_dump($request));
  4. $campaign_array = explode(',',$request->campaign_array); // creates an array from the comma delimited string
  5. $response = get_campaign_summary($campaign_array,$request->filter,$request->column,$request->page,$request->size,false,false);
  6. log_message(log_var_dump("RESPONSE: " . $response));
  7. break;
  8. ........
  9. endswitch;
  10. echo json_encode($response);
  11. exit(0);


I know this is a lot to look at, and will probably be quite confusing. I will attempt to answer any questions. If need be, I can try attaching the full files (including the page HTML and query), but I'm trying to show only what I think is really needed.
As I said, I  have taken over someone else's code, and I myself am having difficulty with it. It seems over complicated, but this is what I have to work with.

In campaigns.js, I can see that the query has run and I have the correct information in "data"

I am just not sure how to get the  campaign_summary.table to reload with this new data.

Thanks in advance for any and all help.