I work on asp.net mvc project . i face issue width of table increase after add filter search individually for every column
so exactly i need give same width filter search exactly as same width of header
so How to solve this issue please ?
what i try as below :
JavaScript
@Html.DisplayNameFor(model => model.RequestNo)
@Html.DisplayNameFor(model => model.EmpID).ToString().Replace(":", "")
@Html.DisplayNameFor(model => model.EmpName).ToString().Replace(":", "")
View Form
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.RequestNo)
@Html.DisplayFor(modelItem => item.EmpID)
@Html.DisplayFor(modelItem => item.EmpName)
@Html.ActionLink("View Form", "Details", new { id = item.RequestNo })
}
RequestNo
EmpID
EmpName
$(document).ready(function () {
new DataTable('#dtbl', {
"dom": 'rtip',
initComplete: function () {
$('#dtbl tfoot tr').insertAfter($('#dtbl thead tr'))
this.api()
.columns()
.every(function () {
let column = this;
let title = column.footer().textContent;
//Create input element
let input = document.createElement('input');
input.placeholder = title;
column.footer().replaceChildren(input);
//var input = $('');
//// Append input element to the footer cell
//$(column.footer()).html(input);
// Event listener for user input
input.addEventListener('keyup', () => {
if (column.search() !== this.value) {
column.search(input.value).draw();
}
});
});
}
});
});
Tahir AnsariRank #366 · 6.8K reputationPosted Oct 14, 2023, 11:58 AM EDT
try below code
$(document).ready(function () { var table = $('#dtbl').DataTable({ "dom": 'rtip', initComplete: function () { $('#dtbl tfoot tr').insertAfter($('#dtbl thead tr')); this.api() .columns() .every(function () { var column = this; var title = $(column.header()).text(); // Create input element var input = document.createElement('input'); input.placeholder = title; $(input).css("width", "100%"); // Set the input width to 100% column.footer().innerHTML = ''; // Clear the footer cell column.footer().appendChild(input); // Add the input element // Event listener for user input input.addEventListener('input', function () { column.search(input.value).draw(); }); }); } }); });Tahir AnsariRank #366 · 6.8K reputationPosted Oct 14, 2023, 12:00 PM EDT
you can address this issue by ensuring that the filter search inputs have the same width as the corresponding table headers.