自动取消jqgrid请求 [英] Automatically cancelling jqgrid request

查看:44
本文介绍了自动取消jqgrid请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个答案:

I'm aware of this answer: How do I add a cancel button to my jqgrid?, and I'm attempting to implement something similar, although without a button to trigger the cancel. Iv'e got a grid that loads on page load (a search that by default loads with no criteria) and I'd like to be able to cancel that default empty criteria search when the user actually executes a search with criteria. Since I don't need a button I'm trying to simplify the solution by merely keeping track of the xhr request in the loadBeforeSend method, and abort that xhr if it is not null as I load the grid. Code:

var gridXhr;
function getGridData() {
    var searchParms = ...;
    var colHeaders = [...];
    var colDefinitions = [...];
    if (gridXhr != null) {
        alert(gridXhr.readyState);
        gridXhr.abort();
        gridXhr = null;
    }
    $('#grid').jqGrid('GridUnload');
    $('#grid').jqGrid({
        defaults: {...},
        autowidth:true,
        url: "<%= Page.Request.Path %>/ExecuteSearch",
        mtype: 'POST',
        ajaxGridOptions: { contentType: "application/json" },
        postData: searchParms,
        datatype: "json",
        prmNames: {
            nd: null,
            rows: null,
            page: null,
            sort: null,
            order: null
        },
        jsonReader: {
            root: function (obj) { return obj.d; },
            page: function (obj) { return 1; },
            total: function (obj) { return (obj.d.length / 20); },
            records: function (obj) { return obj.d.length; },
            id: 'CatalogID',
            cell: '',
            repeatitems: false
        },
        loadonce: true,
        colNames: colHeaders,
        colModel: colDefinitions,
        caption: "Search Results",
        pager: 'searchPaging',
        viewrecords: true,
        loadBeforeSend: function (xhr) {
            gridXhr = xhr;
        },
        loadError: function (xhr, status, error) {
            gridXhr = null;
            if (error != 'abort') {
                alert("Load Error:" + status + "\n" + error);
            }
        },
        loadComplete: function() {
            gridXhr = null;
        },
        multiselect: <%= this.MultiSelect.ToString().ToLower() %>,
        multiboxonly: true
    }).setGridWidth(popWidth);
}

我遇到的问题是jqGrid的后续执行不起作用.触发loadError函数,错误(第3个参数)为中止".我是否需要像其他答案中那样对loadBeforeSend做更多/不同的事情?

The problem I'm having is that subsequent executions of the jqGrid don't work. The loadError function is triggered, with an error (3rd parameter) of "abort." Do I need to do something more/different with the loadBeforeSend as done in the other answer?

此外,Oleg在他的示例代码myGrid[0].endReq();中提到了这一点,我在文档中找不到任何提及-该功能存在吗?

Also, Oleg mentioned in his sample code myGrid[0].endReq(); and I can find no mention of that in the documentation - does that function exist?

推荐答案

如果我对您的理解正确,则只需更改该行

If I understand you correctly you need just change the line

datatype: "json",

类似

datatype: isSearchParamEmpty(searchParms) ? "local" : "json",

换句话说,如果搜索条件为空,则应使用datatype: "local"而不是datatype: "json"创建网格.网格将保持空白.

In other words you should create grid with datatype: "local" instead of datatype: "json" in case of empty searching criteria. The grid will stay empty.

另外,如果colDefinitionscolHeaders对于不同的搜索条件保持不变,则应该考虑只创建一次jqGrid .除了重新创建网格外,您还可以仅更改postData并调用trigger("reloadGrid").

Additionally you should consider to create jqGrid only once if colDefinitions and colHeaders will stay unchanged for different searching criteria. Instead of recreating of the grid you could change postData only and call trigger("reloadGrid").

这篇关于自动取消jqgrid请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆