根据用户输入过滤jqgrid

根据用户输入过滤jqgrid

本文介绍了根据用户输入过滤jqgrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jqgrid一切正常,除了一个小问题.我在下面定义了postData:

everything is working fine with my jqgrid except a small issue. i have defined postData below:

 $(document).ready(function() {

$("#ctl00_ContentPlaceHolder2_drpUSite").change(function() {
    site = ($("#ctl00_ContentPlaceHolder2_drpUSite").val());
    loadusergrid();
});
var usrparams = new Object();
var site = ($("#ctl00_ContentPlaceHolder2_drpUSite").val());
//----grid code---------
$("#users").jqGrid({
    prmNames: {
        _search: "isSearch",
        nd: null,
        rows: "numRows",
        page: "page",
        sort: "sortField",
        order: "sortOrder"
    },
    // add by default to avoid webmethod parameter conflicts
    postData: { searchString: '', searchField: '', searchOper: '', sites: site },
    datatype: function(postdata) {
        mtype: "GET",
        $.ajax({
            url: 'Users.aspx/GetUsers',
            type: "POST",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(postdata),
            dataType: "json",
            success: function(data, st) {
                if (st == "success") {
                    var grid = $("#users")[0];
                    var m = JSON.parse(data.d);
                    grid.addJSONData(m);
                }
            },
            error: function() {
                alert("Loading Failed!");
            }
        });
    },
    // this is what jqGrid is looking for in json callback
    jsonReader: {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        cell: "cell",
        id: "login",
        repeatitems: true
    },
    colNames: ['Login', 'First Name', 'Last Name', 'Email', 'Site', 'Role', 'Room', 'UnitID', 'Supervisor', 'Super'],
    colModel: [
    { name: 'login', index: 'login', width: 20 },
    { name: 'fname', index: 'fname', width: 20, hidden: true },
    { name: 'lname', index: 'lname', width: 60, align: "center", sortable: true, searchoptions: { sopt: ['eq', 'ne']} },
    { name: 'email', index: 'email', width: 20, align: "center", sortable: false },
    { name: 'site', index: 'site', width: 50, align: "center", sortable: true, searchoptions: { sopt: ['eq', 'ne']} },
    { name: 'role', index: 'role', width: 15, align: "center", sortable: true, searchoptions: { sopt: ['eq', 'ne']} },
    { name: 'room', index: 'room', width: 30, align: "center", sortable: true },
    { name: 'unitid', index: 'unitid', width: 10, align: "center", sortable: false },
    { name: 'super', index: 'super', width: 20 },

    { name: 'supername', index: 'supername', width: 10, align: "center", sortable: false },
],

    pager: "#pageusers",
    viewrecords: true,
    caption: "Registered Users",
    imgpath: 'themes/steel/images',
    rowNum: 20,
    rowList: [10, 20, 30, 40, 50],
    sortname: "pname",
    sortorder: "desc",
    showpage: true,
    gridModel: true, gridToolbar: true,
    onSelectRow: function(id) {
        var ret = jQuery("#users").getRowData(id);
        accpara.id = ret.id;
        accpara.pname = ret.pname;
        accpara.pid = ret.pid;
        accpara.bld = ret.bld;
        accpara.cname = ret.cname;
        accpara.amt = ret.amt;
        accpara.status = ret.status;
        accpara.notes = ret.notes;
        accpara.lname = ret.lname;
    }
});
jQuery("#users").navGrid('#pageusers', { view: false, del: false, add: false, edit: false },
 {}, // default settings for edit
 {}, // default settings for add
 {}, // delete
 {closeOnEscape: true, multipleSearch: true,
 closeAfterSearch: true
 }, // search options
 {}
 );
$("#users").setGridWidth(1300, true);
$("#users").setGridHeight(500, true);
jQuery("#users").jqGrid('filterToolbar');
//----grid code ends here



   function loadusergrid() {
       $("#users").setGridParam({ page: 1 }, { pgbuttons: true }, { pginput: true }, { postData: { "site": site} }).trigger("reloadGrid");
    }
});

第一次加载页面时,此方法有效.

when page loads for the 1st time, this works..

现在我有4个下拉菜单可以过滤用户.我编写了一个函数,当下拉列表更改时,它会重新加载网格,但是它不起作用..我在这里做错了什么?当我为下拉列表启用回发时,我得到了过滤后的结果.我想避免在我的页面上发回:).现在,我仅将网站下拉列表添加为过滤器.一旦开始无法正常工作,请添加其余的3.

now i have 4 drop-downs which filter users. i have written a function which reloads the grid when the dropdown is changed, but it isnt working.. what am i doing wrong here?? when i enable postback for the dropdowns, i get the filtered result. i want to avoid postbacks on my page :). right now i have added just the site dropdown as the filter. once this starts working ill add the remaining 3.

firebug显示ajax调用已成功触发,但站点名称为空.请注意,第一次加载页面时,网站下拉列表的值为空.

firebug shows the ajax call is fired successfully but with an empty sitename. please note that the site dropdown cntains an empty value when page is loaded for the 1st time.

预先感谢

推荐答案

$("#mygrid").setPostData({parameters});可以解决问题

这篇关于根据用户输入过滤jqgrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:35