【问题标题】:populate jqgrid with json data from a PHP file使用 PHP 文件中的 json 数据填充 jqgrid
【发布时间】:2014-08-06 11:27:14
【问题描述】:

我对 trirand 的 jqGrid 完全陌生。我有一个基本问题。我有一个调用 php 文件的表单,后者在提交按钮后回显 JSON 响应。我可以按照手册中提到的 jqGrid 所需的形式格式化 JSON 数据。但是如何在不使用另一个按钮的情况下填充它。我试过了:

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

我的意思是如何触发网格读取php文件发送的数据?

【问题讨论】:

    标签: php json jqgrid triggers


    【解决方案1】:
    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++;
      })
    }
    

    【讨论】:

      【解决方案2】:

      在收到这样的搜索结果后尝试触发reloadGrid 事件:

       $('#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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        • 2011-04-24
        • 1970-01-01
        • 2015-07-08
        相关资源
        最近更新 更多