如何使用来自另一个URL的新数据重新加载jqxGrid数据

时间:2015-04-11 16:49:54

标签: jquery ajax jqxgrid

我有一个jqxGrid格式的JqWidgets库,我将数据绑定到jqxGrid就像这样..

 var url = "getConsignments.php?type="+$('#selectIsDelevered').val();

      var consignmentsource =
          {
            datafields: [
              {
                name: 'ConsignmentId', type: 'string'  }
              ,{
                name: 'Name' , type: 'string' }

            ],
            id: 'ConsignmentId',
            datatype: "json",
            async: false,
            cache:false,
            url: url ,
            filter: function()
      {
        // update the grid and send a request to the server.
        $("#jqxgrid").jqxGrid('updatebounddata', 'filter');
      },
      sort: function()
        {
          // update the grid and send a request to the server.
          $("#jqxgrid").jqxGrid('updatebounddata', 'sort');

        },
          root: 'Rows',
          cache: false,
    beforeprocessing: function(data)
    {   
      if (data != null)
      {
        consignmentsource.totalrecords = data[0].TotalRows;          
      }
    }
          }

这适用于虚拟化和服务器调用。 波纹管代码用于绑定我从服务器获取的数据

consignmentAdapter = new $.jqx.dataAdapter(consignmentsource);

  $("#jqxgrid").jqxGrid(
      {
        source: consignmentAdapter,
        theme:'bootstrap',
        columnsresize:true,
        width: '100%',

          filterable:true,
        autoheight:true,

        rowdetails: true,
        autorowheight :true,
        showfilterrow: true,
        pageable:true,
        sortable: true,
        virtualmode: true,
        rendergridrows: function()
        {
            return consignmentAdapter.records;     
        },


        ready: function () {
          // $("#jqxgrid").jqxGrid('showrowdetails', 1);
        }
        ,
        columns: [
          {
            text: 'ID', width: '10%',datafield:  'ConsignmentId'}
          ,
          {
            text: 'Name', datafield: 'Name', width: '18%' }
        ]
      }
    );

selectIsDelevered是一个select标签,有3个选项,每个选项都会加载不同的数据,我会用('#selectIsDelevered').change()函数重新绑定,重新加载或刷新网格 我已经测试了$('#jqxGrid').jqxGrid('updatebounddata');但它没有用,即使我已经尝试$('#jqxGrid').jqxGrid('refresh');重复绑定步骤。 我带了3天,有什么建议吗?!!

1 个答案:

答案 0 :(得分:3)

您可以直接更改网址,如下面的代码:

('#selectIsDelevered').change({
   var tmpS = $("#jqxgrid").jqxGrid('source');
   tmpS._source.url = "getConsignments.php?type="+$('#selectIsDelevered').val();
   $("#jqxgrid").jqxGrid('source', tmpS);
});
相关问题