Javascript validation for checkboxes in JQuery DataTable
I have a table which is binding with JQuery datatable.
<table id="grid1">
<thead>
<tr>
<th>Name</th>
<th>View</th>
<th>Modify</th>
</tr>
</thead>
</table>
Below is the javascript code for binding the table/grid-
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\""
: "") + "/>";
}
},
]
});
}
Before saving the grid/table data, I want to check at least View or Modify
check box is checked. I need to write a javascript validation function.
This is what I have tried-
function Validate() {
$(grid1.fnGetData()).each(function () {
if ($(.checkbox).is(':checked')) {
return true;
}
else {
return false;
}
});
}
Waiting for the valuable suggestions.
No comments:
Post a Comment