jqGrid Filter Toolbar initial default value

前端 未结 5 2001
天涯浪人
天涯浪人 2020-12-14 22:02

I\'m using jqGrid with the filter toolbar, i need to set an initial default filter value to one of the fields so that only rows with status \'Open\' are displayed by default

5条回答
  •  渐次进展
    2020-12-14 22:06

    There are a few steps to do this:

    1. pass a default value in the column model search options
    2. prevent the default form data load process
    3. trigger a filter toolbar data load when the table is ready

    In a bit more detail:

    Set the grid datatype to local (this prevents the initial data load) and set the default value for the search options:

      $("#mytable").jqGrid({
        datatype: "local",
        colNames:['Keyword','Selected'], 
        colModel:[
         {name:'keyword',
          sortable:true,
          searchoptions: { defaultValue:'golf' }
        },
        {name:'selected',
          sortable:false,
          searchoptions: { }
        },
        ....
        ....
    

    Then add the filter toolbar, set the data type and url, and trigger the load:

      $('#mytable').jqGrid('filterToolbar', {autosearch: true});
      $('#mytable').setGridParam({datatype: 'json', url:'/get_data.php'});
      $('#mytable')[0].triggerToolbar();
    

提交回复
热议问题