JQueryデータテーブルにバインドされているテーブルがあります。
<table id="grid1">
<thead>
<tr>
<th>Name</th>
<th>View</th>
<th>Modify</th>
</tr>
</thead>
</table>
以下は、テーブル/グリッドをバインドするための JavaScript コードです。
function grid1_LoadData() {
grid1.fnDestroy();
grid1.dataTable({
"sScrollY": "200px",
"bStateSave": true,
'bDeferRender': true,
'sAjaxSource': '/controller/GetData,
'aoColumns': [
{ 'mDataProp': 'Name' },
{ 'mDataProp': 'View', "sWidth": "55%", sType: 'bool', bSearchable: false, bSortable: false, mData: 'View',
"mRender": function (data, type, full) {
return "<input class=\"enabledbool\" name=\"CanView" + full.ID + "\" type=\"checkbox\" " + (data ? " checked=\"true\"" : "") + "/>";
}
},
{ 'mDataProp': 'Modify', "sWidth": "65%", sType: 'bool', bSearchable: false, bSortable: false, mData: 'Modify', "mRender": function (data, type, full) {
// console.log(data);
return "<input class=\"enabledbool\" name=\"CanModify" + full.ID + "\" type=\"checkbox\" " + (data ? " checked=\"true\"" : "") + "/>";
}
},
]
});
}
グリッド/テーブル データを保存する前に、少なくともチェック ボックスView
またはModify
チェック ボックスをオンにしたい。JavaScript検証関数を書く必要があります。
これは私が試したことです-
function Validate() {
$(grid1.fnGetData()).each(function () {
if ($(.checkbox).is(':checked')) {
return true;
}
else {
return false;
}
});
}
貴重なご提案お待ちしております。
更新 検証を確認するために、以下のjavascript関数を使用することになりました-
function Validate() {
var allOk = true;
$(grid1).find("tbody tr").each(function (){
var row = $(this);
if (!row.Modify && !row.View) {
allOk = false;
}
});
return allOk; // Make `Validate` return true only if all rows validate.
}
私がやろうとしていたのは、 ifModify
とView
are not checked then returnfalse
でした。$(gridProfiles.fnGetData()).each(function ()
の代わりに で確認したところ$(grid1).find("tbody tr").each(function ()
、問題ありませんでした。ただし、グリッド行は動的に追加され、最後に追加された行は を使用するとリストされません$(gridProfiles.fnGetData()).each(function ()
。解決策はありますか?