簡體   English   中英

如何使用按鈕重新綁定jqgrid

[英]how to rebind jqgrid with a button

我想重新綁定我的jqgrid。 這是綁定網格的腳本代碼:

  $(document).ready(function () {

        var categoryId = $('#<%=hdnCategoryId.ClientID %>').val();

        var productName = $('#tags').val();

        jQuery("#tblList").jqGrid({
            url: 'ArenaProductList.aspx/GroupProductList',
            mtype: 'POST',
            datatype: 'json',
            postData: {
                sidx: '',
                sord: '',
                page: '',
                rows: '',
                categoryId: categoryId,
                productName: productName
            },
            ajaxGridOptions: { contentType: "application/json" },
            serializeGridData: function (postData) {
                var propertyName, propertyValue, dataToSend = {};
                for (propertyName in postData) {
                    if (postData.hasOwnProperty(propertyName)) {
                        propertyValue = postData[propertyName];
                        if ($.isFunction(propertyValue)) {
                            dataToSend[propertyName] = propertyValue();
                        } else {
                            dataToSend[propertyName] = propertyValue;
                        }
                    }
                }
                return JSON.stringify(dataToSend);
            },
            jsonReader: {
                root: "d.rows",
                page: "d.page",
                total: "d.total",
                records: "d.records"
            },
            colNames: ['ArenaProductId', 'Açıklama', 'Ana Kategori', 'Alt Kategori', 'Marka', 'KDV', 'Stok', 'Bayi Fiyatı', 'Son Kullanıcı Fiyatı', 'Para Birimi', 'Yüzde'],
            colModel: [
                { name: 'ArenaProductId', index: 'ArenaProductId', hidden: true },
                { name: 'Description1', index: 'Description1', width: 150 },
                { name: 'MainGroupCode', index: 'MainGroupCode', width: 150 },
                { name: 'SubGroupCode', index: 'SubGroupCode', hidden: true },
                { name: 'Brand', index: 'Brand', width: 220 },
                { name: 'Kdv', index: 'Kdv', width: 120 },
                { name: 'Stock', index: 'Stock', width: 100 },
                { name: 'DealerPrice', index: 'DealerPrice', width: 100 },
                { name: 'Price', index: 'Price', width: 100 },
                { name: 'Currency', index: 'Currency', width: 100 },
                { name: 'Rate', index: 'Rate', width: 100 }
            ],
            pager: '#tblPager',
            rowList: [10, 20, 30],
            sortname: 'UserId',
            sortorder: 'desc',
            rowNum: 10,
            loadtext: "Yukleniyor....",
            shrinkToFit: false,
            multiselect: false,
            emptyrecords: "Kayit Bulunamadi",
            autowidth: true,
            shrinkToFit: true,
            height: "400",
            width: "740",
            rownumbers: true,
            //subGrid: true,
            caption: 'Arena Ürünler'
        });
        jQuery("#tblList").jqGrid('navGrid', '#prod_pager',
            { edit: false, add: false, del: false, excel: false, search: false });

        $('#ddlSubCategory').change(function () {
            $('#tags').val('');
            $('#<%=hdnCategoryId.ClientID %>').val($('#<%=ddlSubCategory.ClientID %>').val());
            jQuery("#tblList").trigger('reloadGrid');
        });

        $('#ddlMainCategory').change(function () {
            $('#tags').val('');
            $('#<%=hdnCategoryId.ClientID %>').val($('#<%=ddlMainCategory.ClientID %>').val());
            jQuery("#tblList").trigger('reloadGrid');
        });

    });

我有一個提交按鈕。 單擊按鈕后,我想使用不同的productName值重新加載網格。 你有什么建議嗎?

如果您不想將sidxsordpagerows發送到服務器,則應使用

prmNames: { page: null, rows: null, sort: null, order: null }

jqGrid的參數而不是用法

postData: { sidx: '', sord: '', page: '', rows: '' }

要發送categoryIdproductName總是參數作為的實際$('#<%=hdnCategoryId.ClientID %>')$('#tags').val()可以定義categoryIdproductName的屬性postData方法

postData: {
    categoryId: function() { return $('#<%=hdnCategoryId.ClientID %>').val(); },
    productName: function() { return $('#tags').val(); }
}

有關詳細信息,請參見答案 您已經使用了我在答案中建議的serializeGridData代碼。 因此,數據的序列化將正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM