Column Search Boxes Not Posting Back Contents
Column Search Boxes Not Posting Back Contents
Hello,
I cannot access the data from the individual column search boxes during a postback. I am using ASP.NET Core MVC.
Javascript is:
$(document).ready(function () {
$('#Members').DataTable({
"processing": true,
"serverSide": true,
"searching": false,
"ajax": {
"url": "@Url.Action("GetMembers", "Home")",
"type": 'POST'
},
columns: [
{ "data": "Scn" },
{ "data": "GlobalId" },
{ "data": "Name" },
{ "data": "BoxType" },
{ "data": "Delivery" },
{
data: 'GlobalId', // Use the row's ID for the link
orderable: false,
searchable: false,
render: function (data, type, row) {
// Create an Edit link with the row ID
return '<a href="/Home/' + encodeURIComponent(data) + '">Edit Delivery</a>';
}
}
]
});
$('#Members thead tr:eq(1) th').each(function (i) {
$('input', this).on('keyup change', function () {
if (table.column(i).search() !== this.value) {
table
.column(i)
.search(this.value)
.draw();
}
});
});
});
**The postback works correctly, but the Request.Form variable for each column is never populated:
**
Request.Form[$"columns[{i}][search][value]"]
I disabled the global search box using the property: "searching": false, to disable the global search. Setting this property has no bearing on the Request.Form variables.
Thank you!
This question has an accepted answers - jump to answer
Answers
Your set up looks like it should work there. Can you link to a test case showing the issue please? I would also suggest checking the data submitted to the server in your browser's Network inspector.
Allan
You have
"searching": false,. Setting thesearchingoption tofalsewill disable Datatables searching. Try removing that option.Kevin
Hi Kevin,
I get the same result when I remove the searching option. The request form variables for the text boxes are always an empty string.
The Request Form variables are:
columns[0][search][value]
columns[1][search][value]
etc.
Thanks,
Al
Can you link to a test case so I can debug it please?
Allan
Without a test case it will be difficult to troubleshoot. I built a simple test case here with your code snippet:
https://live.datatables.net/yaroyala/144/edit
I noticed both header rows have the sort icons. When clicking the search input the column is first sorted. If you type into the search input the request has the typed search values, for example:
The sort function can be forced to the top row with
orderCellsTop. Here is the updated example:https://live.datatables.net/jikehibe/1/edit
Notice sorting doesn't happen when clicking into the input and the search works.
If you still have issues with this then please update my test case or provide a link to a page showing the issue so we can help debug.
See this note from the
searchingdocs for how to remove the global search input but allow searching to work.Kevin
Thank you! The code is working after I integrated the ideas from the sample. The ticket can be closed.