如何在不使用 Ajax 请求的情况下加载 jqGrid?

发布于 2024-09-30 03:17:20 字数 288 浏览 3 评论 0原文

我发现/看到的每个 jsGrid 使用示例都显示通过 Ajax 请求加载数据。我想根据已有的数据加载网格;除非是技术要求,否则完全没有必要提出单独的请求。

我真的希望我的控制器能够提取在网格中显示所需的数据,将其传递到我的视图,并让 jqGrid 根据本地数据执行其操作,而不是发起另一个请求。我无法想象这是不可能的,但我还没有找到一个不使用 url 配置来获取 JSON 格式数据的示例。

当然,数据加载器并没有这么狭窄,但是有人可以给我指出一个不以 ajax 为中心的示例吗?

谢谢。

Every single example of jsGrid usage that I've found/seen shows data being loaded through an Ajax request. I'd like to load the grid based on data that's already available; a separate request is completely unnecessary unless it's a technical requirement.

I'd really like my controller to pull the data required for display in the grid, pass it along to my view and let jqGrid do its thing based on that local data rather than initiating another request. I can't imagine that's not possible, but I haven't found even a single example that doesn't use the url configuration to acquire the data in JSON format.

Surely, the data loader isn't this narrow, but can someone point me to an example that isn't ajax-centric?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野味少女 2024-10-07 03:17:20

从3.7版本开始jqgrid已经有了完整的本地支持包括数据排序分页等。

所以你可以使用 datadatastr 参数。 localReader的使用可以参见文档。这是一个简单的例子:

var mydata = [
    { id: "1", invdate: "2007-10-01", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "2", invdate: "2007-10-02", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "3", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "4", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "5", invdate: "2007-10-05", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "6", invdate: "2007-09-06", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "7", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "8", invdate: "2007-10-03", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "9", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "10", invdate: "2007-10-01", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "11", invdate: "2007-10-02", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "12", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "13", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "14", invdate: "2007-10-05", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "15", invdate: "2007-09-06", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "16", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "17", invdate: "2007-10-03", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "18", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" }
];
var grid = $("#list");
grid.jqGrid({
    data: mydata,
    datatype: "local",
    colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
    colModel: [
        { name: 'id', index: 'id', key: true, width: 70, sorttype: "int" },
        { name: 'invdate', index: 'invdate', width: 90, sorttype: "date" },
        { name: 'name', index: 'name', width: 100 },
        { name: 'amount', index: 'amount', width: 80, align: "right", sorttype: "float" },
        { name: 'tax', index: 'tax', width: 80, align: "right", sorttype: "float" },
        { name: 'total', index: 'total', width: 80, align: "right", sorttype: "float" },
        { name: 'note', index: 'note', width: 150, sortable: false }
    ],
    pager: '#pager',
    rowNum: 10,
    rowList: [5, 10, 20, 50],
    sortname: 'id',
    sortorder: 'asc',
    viewrecords: true,
    height: "100%",
    caption: "Simple loading of local data"
});
grid.jqGrid('navGrid', '#pager', { add: false, edit: false, del: false, search: true, refresh: true });

Starting with the version 3.7 jqgrid has full local support including data sorting paging and so on.

So yo can use data or datastr parameter. The usage of localReader can be needed see documentation. Here is simple example:

var mydata = [
    { id: "1", invdate: "2007-10-01", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "2", invdate: "2007-10-02", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "3", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "4", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "5", invdate: "2007-10-05", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "6", invdate: "2007-09-06", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "7", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "8", invdate: "2007-10-03", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "9", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "10", invdate: "2007-10-01", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "11", invdate: "2007-10-02", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "12", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "13", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "14", invdate: "2007-10-05", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "15", invdate: "2007-09-06", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "16", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "17", invdate: "2007-10-03", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "18", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" }
];
var grid = $("#list");
grid.jqGrid({
    data: mydata,
    datatype: "local",
    colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
    colModel: [
        { name: 'id', index: 'id', key: true, width: 70, sorttype: "int" },
        { name: 'invdate', index: 'invdate', width: 90, sorttype: "date" },
        { name: 'name', index: 'name', width: 100 },
        { name: 'amount', index: 'amount', width: 80, align: "right", sorttype: "float" },
        { name: 'tax', index: 'tax', width: 80, align: "right", sorttype: "float" },
        { name: 'total', index: 'total', width: 80, align: "right", sorttype: "float" },
        { name: 'note', index: 'note', width: 150, sortable: false }
    ],
    pager: '#pager',
    rowNum: 10,
    rowList: [5, 10, 20, 50],
    sortname: 'id',
    sortorder: 'asc',
    viewrecords: true,
    height: "100%",
    caption: "Simple loading of local data"
});
grid.jqGrid('navGrid', '#pager', { add: false, edit: false, del: false, search: true, refresh: true });
澉约 2024-10-07 03:17:20

请查看此处的 jqGrid 示例。展开“加载数据”并单击“数组数据”。

Look at the jqGrid examples here. Expand 'Loading data' and click on 'Array data'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文