如何在JQGRID中使用keyup事件进行过滤?

时间:2014-02-21 10:37:59

标签: ajax jqgrid keyup

这是我的代码:

$("#txName").keyup(function(){
  var contributie = $('#txName').val();
  $.get( "/contributii/populateGrid/", { contributie: contributie} )
    .done(function( data ) {
      jQuery("#contributionList").trigger("reloadGrid");
    });

});

jQuery("#contributionList").jqGrid({ 
    url:'/contributii/populateGrid/', 
    datatype: "json", 
    colNames:['Data','Titlu', ' ','Autor','Categorie'], 
    colModel:[ 
      {name:'data',index:'data', width:'300px'},  
      {name:'titlu',index:'titlu', width:'400px'}, 
      {name:'comentarii',index:'comentarii', width:'100px'},
      {name:'autor',index:'autor', width:'200px'},
      {name:'categorie',index:'categorie', width:'400px'}
    ], 
    rowNum:10, 
    viewrecords: true, 
    sortorder: "desc",
    height:'auto'
});

此代码总是返回相同的网格,因为它在keyup事件上执行了两次。我想知道我该怎么处理? THX

2 个答案:

答案 0 :(得分:0)

解决方案:

jQuery("#contributionList").jqGrid({ 
    url:'/contributii/populateGrid/', 
    postData: {
        contributie: function() { return $("#txName").val(); }
    },
    datatype: "json", 
    colNames:['Data','Titlu', ' ','Autor','Categorie'], 
    colModel:[ 
      {name:'data',index:'data', width:'300px'},  
      {name:'titlu',index:'titlu', width:'400px'}, 
      {name:'comentarii',index:'comentarii', width:'100px'},
      {name:'autor',index:'autor', width:'200px'},
      {name:'categorie',index:'categorie', width:'400px'}
    ], 
    rowNum:10, 
    viewrecords: true, 
    sortorder: "desc",
    height:'auto'
});

答案 1 :(得分:0)

试试这个:

    jQuery("#contributionList").jqGrid({ 
    url:'/contributii/populateGrid/',
    postData: {
        contributie: $("#txName").val()
    },
    mtype: 'POST',
    datatype: "json", 
    colNames:['Data','Titlu', ' ','Autor','Categorie'], 
    colModel:[ 
      {name:'data',index:'data', width:'300px'},  
      {name:'titlu',index:'titlu', width:'400px'}, 
      {name:'comentarii',index:'comentarii', width:'100px'},
      {name:'autor',index:'autor', width:'200px'},
      {name:'categorie',index:'categorie', width:'400px'}
    ], 
    rowNum:10, 
    viewrecords: true, 
    sortorder: "desc",
    height:'auto'
});

// Keyup event
$("#txName").keyup(function(){
    jQuery("#contributionList").jqGrid('setGridParam', {
        url:'/contributii/populateGrid/',
        postData: {
            contributie: $("#txName").val()
        },
   }).trigger('reloadGrid');
});