jqGrid 随机检查复选框列
jqGrid randomly checks checkbox column
我正在使用 jqGrid 将 Json 对象转换为常规 HTML table。从服务器我得到对象,除了一件事之外一切都很好。我添加了一列,实际上是复选框列。在每个复选框输入的值属性中,我放置了 ID,如果复选框被选中,我稍后会传回服务器。
$("#membersGrid").jqGrid({
url: '/Member/GetAllMembers',
mtype: "GET",
styleUI: 'Bootstrap',
datatype: "json",
colModel: [
{ label: 'Full Name', name: 'fullName', width: 150 },
{
label: 'Select', editable: true, name: 'id',
edittype: 'checkbox', editoptions: { value: "true:false", defaultValue: "false" },
formatter: "checkbox", formatoptions: { disabled: false }, width: 45
}
],
viewrecords: true,
height: 250,
width: 640,
rowNum: -1,
ajaxSubgridOptions: { async: false },
});
当为值生成复选框列时,我定义了 true 或 false 并且使用 defaultValue 我想声明 false(未选中)是每个生成的带有复选框的单元格的默认值。
但是我得到的是随机选中的复选框:
当我检查 Chrome 中的元素时,以这种方式自动生成未检查的类型:
<td role="gridcell" style="" title="" aria-describedby="membersGrid_id">
<input type="checkbox" value="400" offval="no">
</td>
并检查类型如下:
<td role="gridcell" style="" title="" aria-describedby="membersGrid_id">
<input type="checkbox" checked="checked" value="399" offval="no">
</td>
是否有其他方法告诉 jqGrid 避免使用 defaultValue
属性检查复选框?还是我做错了什么?
我认为formatter: "checkbox"
的用法存在误解。它将输入值 true
或 false
显示为复选框的 checked/unchecked 状态。输入数据的属性id
将作为rowid:行的id
属性的值(<tr>
元素网格)。
因此,我建议您更改 name
或将包含复选框的列。您的主要问题应该已经解决了。
我建议您谨慎使用 formatter: "checkbox", formatoptions: { disabled: false }
。 jqGrid 支持三种编辑模式:单元格编辑、内联编辑和表单编辑,允许修改jqGrid 的本地数据。此外,您目前不使用 loadonce: true
选项。因此根本不会创建任何本地数据:只有 HTML table 中的数据将保存从服务器返回的信息。复选框 formatter: "checkbox", formatoptions: { disabled: false }
的更改将不会被跟踪,您在读取数据时可能会遇到问题。一切都取决于如何你读取复选框的数据...The demo, which I created for the answer,显示如何修改 jqGrid 的 local 数据以便保存复选框的状态。
我正在使用 jqGrid 将 Json 对象转换为常规 HTML table。从服务器我得到对象,除了一件事之外一切都很好。我添加了一列,实际上是复选框列。在每个复选框输入的值属性中,我放置了 ID,如果复选框被选中,我稍后会传回服务器。
$("#membersGrid").jqGrid({
url: '/Member/GetAllMembers',
mtype: "GET",
styleUI: 'Bootstrap',
datatype: "json",
colModel: [
{ label: 'Full Name', name: 'fullName', width: 150 },
{
label: 'Select', editable: true, name: 'id',
edittype: 'checkbox', editoptions: { value: "true:false", defaultValue: "false" },
formatter: "checkbox", formatoptions: { disabled: false }, width: 45
}
],
viewrecords: true,
height: 250,
width: 640,
rowNum: -1,
ajaxSubgridOptions: { async: false },
});
当为值生成复选框列时,我定义了 true 或 false 并且使用 defaultValue 我想声明 false(未选中)是每个生成的带有复选框的单元格的默认值。
但是我得到的是随机选中的复选框:
当我检查 Chrome 中的元素时,以这种方式自动生成未检查的类型:
<td role="gridcell" style="" title="" aria-describedby="membersGrid_id">
<input type="checkbox" value="400" offval="no">
</td>
并检查类型如下:
<td role="gridcell" style="" title="" aria-describedby="membersGrid_id">
<input type="checkbox" checked="checked" value="399" offval="no">
</td>
是否有其他方法告诉 jqGrid 避免使用 defaultValue
属性检查复选框?还是我做错了什么?
我认为formatter: "checkbox"
的用法存在误解。它将输入值 true
或 false
显示为复选框的 checked/unchecked 状态。输入数据的属性id
将作为rowid:行的id
属性的值(<tr>
元素网格)。
因此,我建议您更改 name
或将包含复选框的列。您的主要问题应该已经解决了。
我建议您谨慎使用 formatter: "checkbox", formatoptions: { disabled: false }
。 jqGrid 支持三种编辑模式:单元格编辑、内联编辑和表单编辑,允许修改jqGrid 的本地数据。此外,您目前不使用 loadonce: true
选项。因此根本不会创建任何本地数据:只有 HTML table 中的数据将保存从服务器返回的信息。复选框 formatter: "checkbox", formatoptions: { disabled: false }
的更改将不会被跟踪,您在读取数据时可能会遇到问题。一切都取决于如何你读取复选框的数据...The demo, which I created for the answer,显示如何修改 jqGrid 的 local 数据以便保存复选框的状态。