Javascript 搜索和排序在JqGrid(json)中不起作用
我在JqGrid工作。 我有一些来自服务器的JSONJavascript 搜索和排序在JqGrid(json)中不起作用,javascript,jquery,asp.net-mvc,json,jqgrid,Javascript,Jquery,Asp.net Mvc,Json,Jqgrid,我在JqGrid工作。 我有一些来自服务器的JSON [{"Id":1,"Name":"product1","Price":234,"Size":"Small"},{"Id":18,"Name":"product2","Price":3242,"Size":"Large"}] 和Jquery代码 $("#table").jqGrid({ url: '@Url.Action("GetProductsAtJSON", "Product")', dat
[{"Id":1,"Name":"product1","Price":234,"Size":"Small"},{"Id":18,"Name":"product2","Price":3242,"Size":"Large"}]
和Jquery代码
$("#table").jqGrid({
url: '@Url.Action("GetProductsAtJSON", "Product")',
datatype: 'json',
mtype: 'GET',
colNames: ['Id', 'Name', 'Price', 'Size'],
colModel: [
{ name: 'Id', index: 'Id', width: 55, key: true, editable: true, editoptions: { readonly: true }, sortable: true, search:true },
{ name: 'Name', index: 'Name', width: 150, editable: true, editoptions: { size: 25 }, editrules: { required: true }, search: true },
{ name: 'Price', index: 'Price', width: 100, align: 'center', editable: true, editoptions: { size: 25 }, editrules: { required: true, number: true, minValue: 1, maxValue: 10000 } },
{ name: 'Size', index: 'Size', width: 150, editable: true, edittype: "select", editoptions: { value: "0:Large;1:Medium;2:Small" } }
],
pager: '#pager',
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'Id',
sortorder: "asc",
viewrecords: true,
caption: 'All product',
height: '400',
jsonReader: {
repeatitems: false,
loadonce: true,
id: "Id",
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
});
我已经阅读了文档和很多论坛,但我不明白为什么排序和搜索不起作用。也许我的JSON格式不正确,我必须写总页面记录,但这也不起作用。我使用key:true from rows id,但它不起作用
我做错了什么?您的代码中有一些小错误: loadonce:true是jqGrid选项,而不是jsonReader的属性 对于内容不应解释为文本的列,应使用sorttype属性。例如,您应该将sorttype:integer添加到“Id”和“Price”列的定义中 我建议您考虑值编辑选项:{值:0:大;1:中等;2:小}是您需要的。这将是重要的版本只。 另外,我建议您使用gridview:true来提高网格的性能,使用autoencode:true将JSON输入中的值解释为文本而不是HTML片段,并使用height:“auto”来更好地显示网格。 要在本地搜索数据,您需要使用或。
是修复代码的一个示例。它是否返回到带有字符串的操作?在操作中,我得到带有排序参数的字符串。。。我不知道。。如何使用客户端排序?当我在服务器端使用数据类型json排序和搜索工作时?我只想简单地说,JQGrid基本上是一个AJAX控制的服务器端,我使用navGrid:很棒!谢谢你的演示!这是正确的工作,我谷歌4-5小时。。。