基于用户输入的jqGrid滤波(filtering jqgrid based on user inp

2019-09-29 16:13发布

一切都与我的jqGrid工作的罚款只是一个小问题。 我已经定义POSTDATA下面:

 $(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");
    }
});

当页面加载的第一时间,该工程..

现在我有4个下拉菜单,其过滤器的用户。 我写这重新加载时下拉被改变电网的功能,但它不是工作..我到底做错了什么? 当我启用的下拉列表回发,我得到的过滤结果。 我想避免在我的网页:)回发。 现在我已经加入只是网站下拉列表作为过滤器。 一旦这个开始工作生病加入剩余的3。

萤火显示Ajax调用成功发射,但与空站点名。 请注意,当页面加载的第一时间在网站下拉cntains空值。

提前致谢

Answer 1:

$("#mygrid").setPostData({parameters}); 不会把戏



文章来源: filtering jqgrid based on user input