http://www.trirand.com/blog/jqgrid/jqgrid.html
我有一个 5 列的 jqgrid,第一列作为操作,在第一列中我有 3 个按钮作为编辑、保存、取消。当我将数据列表绑定到 jqgrid 时,我有 2 个问题......首先列中的数据被放错了位置,因为第一列有 3 个按钮,列表列中的数据是第一个绑定的具有作为列名的操作的网格列和所有其他列数据都被放错了位置
当我单击操作列中的编辑按钮时,网格中的所有行都支持包括操作列在内的内联编辑功能,因此没有单击保存的选项。
我的 jQuery 代码:
<script type="text/javascript">
$(function () {
var lastsel;
jQuery("#list").jqGrid({
url: '/Home/GetStudents/',
datatype: 'json',
mtype: 'POST',
colNames: ['Actions', 'StudentID', 'FirstName', 'LastName', 'Email'],
colModel: [
{ name: 'act', index: 'act', width: 75, sortable: false },
{ name: 'StudentID', sortable: false, key: true },
{ name: 'FirstName', key: true },
{ name: 'LastName', sortable: false, key: true },
{ name: 'Email', width: 200, sortable: false, key: true}],
cmTemplate: { align: 'center', editable: true },
pager: '#pager',
width: 750,
rowNum: 15,
rowList: [5, 10, 20, 50],
sortname: 'StudentID',
sortorder: "asc",
viewrecords: true,
caption: ' My First JQgrid',
gridComplete: function () {
var ids = jQuery("#list").jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++) {
var cl = ids[i];
be = "<input style='height:22px;width:20px;' type='button' value='E' onclick=\"jQuery('#list').editRow('" + cl + "');\" />";
se = "<input style='height:22px;width:20px;' type='button' value='S' onclick=\"jQuery('#list').saveRow('" + cl + "');\" />";
ce = "<input style='height:22px;width:20px;' type='button' value='C' onclick=\"jQuery('#list').restoreRow('" + cl + "');\" />";
jQuery("#list").jqGrid('setRowData', ids[i], { act: be + se + ce });
}
},
editurl: '/Home/About/',
// data: { get_param: selectedDescription },
caption: "jQgrid Sample"
});
jQuery("#list").jqGrid('navGrid', "#prowed2", { edit: false, add: false, del: false });
});
</script>