我是 JqGrid 的新手。我使用以下代码来网格化我的数据:
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#grid_table").jqGrid({
url: '@Url.Action("GetAll", "Widget")',
datatype: "json",
mtype: 'POST',
colNames: ['ReadDate', 'Name'],
colModel: [
{ name: 'ReadDate', index: 'ReadDate', width: 200, sortable: true, editable: false, editoptions: { readonly: true, size: 10} },
{ name: 'Name', index: 'Name', width: 500, editable: false }
],
jsonReader: {
root: "rows", //array containing actual data
page: "page", //current page
total: "total", //total pages for the query
records: "records", //total number of records
repeatitems: false,
id: "id" //index of the column with the PK in it
},
rowNum: 20,
rowList: [20, 30],
pager: jQuery('#gridpager'),
sortname: 'Name',
viewrecords: true,
sortorder: "asc",
width:968,
height:349
}).navGrid('#gridpager');
});
</script>
代码有效。我无法使用 json 从服务器获取数据。但我也想动态获取 colNames。我找不到有关此主题的任何文档。如何动态获取 colNames 和 colModels?
像这样的东西:
colNames: data.colNames,
colModel: data.colModels,
提前致谢。