我发现/看到的每个 jsGrid 使用示例都显示了通过 Ajax 请求加载的数据。我想根据已经可用的数据加载网格;除非是技术要求,否则完全不需要单独的请求。
我真的希望我的控制器提取在网格中显示所需的数据,将其传递给我的视图,并让 jqGrid 根据该本地数据执行其操作,而不是发起另一个请求。我无法想象这是不可能的,但我什至没有找到一个不使用url
配置来获取 JSON 格式数据的示例。
当然,数据加载器并不是那么狭窄,但是有人可以指出一个不以 ajax 为中心的示例吗?
谢谢。
我发现/看到的每个 jsGrid 使用示例都显示了通过 Ajax 请求加载的数据。我想根据已经可用的数据加载网格;除非是技术要求,否则完全不需要单独的请求。
我真的希望我的控制器提取在网格中显示所需的数据,将其传递给我的视图,并让 jqGrid 根据该本地数据执行其操作,而不是发起另一个请求。我无法想象这是不可能的,但我什至没有找到一个不使用url
配置来获取 JSON 格式数据的示例。
当然,数据加载器并不是那么狭窄,但是有人可以指出一个不以 ajax 为中心的示例吗?
谢谢。
从 3.7 版本开始,jqgrid 具有完整的本地支持,包括数据排序分页等。
所以你可以使用data
或datastr
参数。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 });
在这里查看 jqGrid 示例。展开“加载数据”并单击“数组数据”。