0

当行数为零并应用过滤器时,如何避免从 jQgrid 获得异常。我的代码看起来像这样

function filterGrid(grid, siteId, buildingId, cityId, selectedType) {   
        var today = new Date();
        var dd = today.getDate();
        var mm = today.getMonth() + 1; //January is 0!

        var yyyy = today.getFullYear();
        if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm } today = mm + '/' + dd + '/' + yyyy;

        if (cityId == -1) {
            grid.setGridParam({ search: false });
        }
        else {
            var filter = { groupOp: "AND", rules: [{ field: "CityID", op: "eq", data: cityId}] };

            if (siteId >= 0)
                filter = { groupOp: "AND", rules: [{ field: "CityID", op: "eq", data: cityId }, { field: "SiteID", op: "eq", data: siteId}] }; // , { field: "BuildingID", op: "eq", data: buildingId}

            if (buildingId >= 0)
                filter = { groupOp: "AND", rules: [{ field: "CityID", op: "eq", data: cityId }, { field: "SiteID", op: "eq", data: siteId }, { field: "BuildingID", op: "eq", data: buildingId}] };

            if (selectedType == "Outstanding Books")
                filter = { groupOp: "AND", rules: [{ field: "CityID", op: "eq", data: cityId }, { field: "SiteID", op: "eq", data: siteId }, { field: "BuildingID", op: "eq", data: buildingId }, { field: "IsReturnDateNull", op: 'eq', data: true }, { field: "DueDate", op: 'gt', data: today}] };

            //For filtering
            grid.setGridParam({ search: true, postData: { filters: JSON.stringify(filter)} });

            //For searching   
            //grid.setGridParam({ search: true, postData: { searchOper: "eq", searchField: "Status", searchString: selectedVal} });
        }

        grid.trigger("reloadGrid");
    }

我编写的代码工作得非常好但是如果数据源没有记录与网格绑定然后我得到一个异常,我想将行数放入服务器端的隐藏字段中,如果行在客户端隐藏字段中的计数为零然后跳过搜索,但是由于在异步回调期间数据源被分配给 jqgrid,因此隐藏字段中的值没有得到更新(总是在客户端的隐藏字段中获取空字符串)所以可以body 帮助我在没有数据绑定时如何避免从 jqgrid 获得空异常。

4

1 回答 1

0

我终于找到了这个问题的答案。我使用了 jqgrid 的事件 onsearching,在服务器端,我从包含当前行的隐藏字段中获取行数,如果行数为 0,则我取消搜索操作。

protected void grdBookTransaction_Searching(object sender, Trirand.Web.UI.WebControls.JQGridSearchEventArgs e)
    {
        if (string.IsNullOrEmpty(GridCount.Value) || GridCount.Value == "0")
        {
            e.Cancel = true;
        }
    }   
于 2013-07-19T08:56:58.603 回答