Trying to Achieve
Using Datatable, I am trying to implement column searching. I wish to pass search[value] and column index to Controller where I have a filter method that will filter and load the list.
What I have tried
With the following code, I bind keyup change to each column. During keyup change, I managed to get valueData and column index from the table
table.columns().eq(0).each(function (colIdx) {
$('input', $('.filters td')[colIdx]).bind('keyup change', function () {
var searchColIndex = $(this).parent().index();
//=== During keyup or change, it will go through each column
var columnIndex = colIdx;
//=== When the searchCol matches the columnIndex
if (searchColIndex == columnIndex) {
//=== Ideally will call Draw and pass the value to Controller
var valuedata = $(this).val();
//table.column(0).search($(this).val()).draw();
table
.column(colIdx)
.search(valuedata)
.draw();
}
});
});
Controllers could not manage to get the search value or column index
But if I search at the top right hand corner search box, Controllers able to request the value
Code https://github.com/BROMVC5/BROSTANDARD.git
Suggested by Murat
var table = $('#tablePassword').DataTable({
"paging": true,
"ordering": true,
"processing": true, // control the processing indicator.
"serverSide": true, // recommended to use serverSide when data is more than 10000 rows for performance reasons
"info": true, // control table information display field
"lengthChange": true,
"lengthMenu": [[5, 20, 50, -1], [5, 20, 50, "All"]], // use the first inner array as the page length values and the second inner array as the displayed options
"colReorder": true,
"orderMulti": true, // for disable multiple column at once
"language": {
searchPlaceholder: "Search records"
},
"order": [["3", "desc"]], //=== Not working during stateSave
//"ajax":{
// "url": "/Password/AjaxGetJsonData",
// "type": "POST"
//},
"AjaxSource": "/Password/AjaxGetJsonData",
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push({ "name": "all", "value": true });
$.getJSON(sSource, aoData, function (json) {
fnCallback(json)
});
},
//*** Added the following code ****
"columnDefs": [
{
"width": "5%", "targets": 'NumCol', "data": "id",
"orderable": false,
"render": function (data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1;
}
},
{
"targets": 'LoginCol',
"data": "LoginID", "orderable": true
},
{
"targets": 'NameCol',
"data": "Name", "orderable": true
},
{
"targets": 'DtCreatedCol',
"data": "DateCreated", "orderable": true
},
{
"targets": 'EditCol', // The third column
"className": "text-center",
"orderable": false,
"render": function (data, type, full, meta) {
return '<a href="/Password/PasswordDet/' + full.AutoINC + '"><img src="../../Content/myPics/edit-2-24.png" ></a>';
}
}
],
});
$('body').on('click', '#btnGet', function () {
//to get currently clicked row object
var row = $(this).parents('tr')[0];
//to get currently clicked row data
var rowData = table.row(row).data();
//to get currently clicked row id (first column value (at index [0])
var rowId = rowData[0];
var row = $(this).closest("tr"), // Finds the closest row <tr>
rowId = row.find("td:nth-child(1)").text();
});
Suggested by Murat Controller is not called and hang





Request.QueryString? and whatHttpVerbare you using onAjaxGetJsonDataGetorPost?GetI have posted the Ajax code and additional stuff.blank/emptystring forsearch[value]is you have enabled"filter": truewhich enabled a search box on the top right corner of your table. And you are trying to call the search from the individual search boxes for each column but the value that you are reading is from the main Search box. So, change the read logic to be something like:columns[index][search][value]to make the search work.