简体   繁体   中英

populate jqgrid with json data from a PHP file

I am absolutely new to trirand's jqGrid. I have a fundamental question. I have a form which calls a php file and the latter echoes a JSON response after a submit button. I can format the JSON data in the form needed by jqGrid as mentioned in the manual. But how do I populate it without using another button. I have tried:

     $("#output_grid").jqGrid({ //grid5 function starts
     url: "searchresults.php",
     datatype: "json",
     mtype: "GET",
     ................
     ................

what I mean is How do I trigger the grid to read the data sent by php file?

function start_post_data(){
  $.post(
      'script.php',
      { a  : 1, 
        b  : 2
      },
      start_get_data_ajax,
      'json'
  );  
}

function start_post_data_ajax(data, statusText, xhr){
  // add the data to the grid
  $("#selectieatable").jqGrid("clearGridData", true).trigger("reloadGrid");
  i=0;
  $.each(data['rows'], function(key, val) {
        jQuery("#selectieatable").jqGrid('addRowData',i+1,data['rows'][key]);  
        i++;
  })
}

Try to trigger the reloadGrid event after you've received your search results like this:

 $('#output_grid').jqGrid('clearGridData'); // Remove previous data
 $('#output_grid').jqGrid({
    url: 'searchresults.php',
    datatype: 'json',
    ...
 }).trigger('reloadGrid', [{ page: 1 }]); // Reload Grid, and start showing page 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM