我正在使用jQuery DataTables并尝试检索是否检查特定列的所有行的复选框。这是尝试根据不同的列值设置自定义筛选。这是一个小代码示例:
$.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex){
//var checkedFilters = Here I get any of my checkboxes out side of datatables that im using to filter.
if(checkedFilters.length{
result = false;
$(checkedFilters).each(function(i, obj){
var $value = '';
var $column = 0;
switch(obj){
case 'Monday':
case 'Tuesday':
case 'Wednesday':
etc, etc.:
$value = $obj;
$column = aData[4]; //This works fine for getting data that is NOT a checkbox
break;
case 'Disabled': // This one is a column of checkbox values
$value = true or checked, or however i need to compare the data;
$column = aData[17]; //unable to get at the state of the checkbox this way.
break;
}
if ($column === $value) {
result = true;
return false;
}
return result;
if(!checkedFilters.length){
return true;
}
return false;
}
});
});
感谢您的帮助!谢谢!
这是第17栏显示的html:
<td id="isDisabled"> //Checked
<input checked="checked" class="check-box" disabled="disabled" type="checkbox" />
</td>
<td id="isDisabled"> //Un-checked
<input class="check-box" disabled="disabled" type="checkbox" />
</td>
答案 0 :(得分:0)
What I ended up doing on this one is updating my view model to take a string value instead of a boolean checkbox value. So now when I query the database, I convert the value to string "True" or "False"... This way I can read the values the same way I am for the Monday - Sunday values:
if(checkedFilters.length{
result = false;
$(checkedFilters).each(function(i, obj){
var $value = '';
var $column = 0;
switch(obj){
case 'Monday':
case 'Tuesday':
case 'Wednesday':
etc, etc.:
$value = $obj;
$column = aData[4]; //This works fine for getting data that is NOT a checkbox
break;
case 'Disabled': // Converted this from boolean to string "True" or "False"
$value = "True"
$column = aData[17]; // Now returns "True" or "False"
break;
}
if ($column === $value) {
result = true;
return false;
}
return result;
if(!checkedFilters.length){
return true;
}
return false;
}
});
});
I had to spend 10 or so more minutes updating my view model, but I didn't have to do anything else extra. I hope this helps anyone else who runs into this.