我需要根据同一行前一列中存在的值来使该行的最后一列禁用或启用。我们已经使用数据表来创建表。
使用mRender
进行比较以呈现数据时,无法获取行单元格中的值。任何人都可以帮助获取mRender
中的行的值吗?
我尝试使用iDataRow
以及createdRow
和fnRowCallback
在创建表后禁用最后一列。
我不知道为什么createdRow
在aoColumns
中不起作用。
请在下面找到我的代码段:
"aoColumns": [{
"mData": "productID",
"bSearchable": true,
"bSortable": true
}, {
"mData": "barcode",
"bSearchable": true,
"bSortable": true
}, {
"mData": "fulfillmentChannel",
"bSearchable": true,
"bSortable": true
}, {
"mData": "dateAvailable",
"bSearchable": true,
"bSortable": true
}, {
"mData": "stockStatus",
"bSearchable": true,
"bSortable": true
}, {
"mData": "stockAllocation",
"mRender": function (data, type, full, iDataRow) {
console.log(iDataRow);
<c:if test="${User.permission eq 'All'}">
return '<input type="text" class="form-control" style="width:100%" id="stockAllocation" validationDescription="<spring:message code="validation.mustBeDigit"></spring:message>" validationRules="^[0-9]+$" name="stockAllocation" value="' + data + '"></input>';
</c:if>
<c:if test="${User.permission eq 'ReadOnly'}">
return data;
</c:if >
},
"bSearchable": true,
"bSortable": true
}],
我希望将
fullfillmentchannell
和stockAllocation
的值写入mRender
,并写入条件并禁用stockAllocaton
字段。 最佳答案
解
您可以使用full
变量访问行的数据,例如full['fulfillmentChannel']
或full['stockAllocation']
。
然后可以在mRender
函数中编写:
"mRender": function (data, type, full, iDataRow) {
if(full['fulfillmentChannel'] === 'A' && full['stockAllocation'] === 'B'){
data = 'Disabled';
} else {
data = 'Not disabled';
}
return data;
}
演示
有关使用DataTables 1.10的类似示例的演示,请参见this jsFiddle。