ahmedaziz
Well-known member
- Joined
- Feb 22, 2023
- Messages
- 55
- Programming Experience
- 1-3
I work on an ANSP.net MVC app, and I face the issue that I can't add text input filter on top of every column to filter data related to every column with another, meaning I have data table have 3 columns RequestNo and EmpId and EmpName.
So I will add 3 input box filter for 3 column every column from requestNo and EmpId and EmpName.
So the shape will be:
RequestNo EmpId EmpName
input text box filter input text box filter input text box filter
every input text box will filter column related to it
How to do it using jQuery or JavaScript?
So I will add 3 input box filter for 3 column every column from requestNo and EmpId and EmpName.
So the shape will be:
RequestNo EmpId EmpName
input text box filter input text box filter input text box filter
every input text box will filter column related to it
How to do it using jQuery or JavaScript?
How to add filter for every column on Datatable:
<table id="dtbl" class="table table-bordered table-hover table-striped" style="width:100%;padding-left:5px;padding-right:7px;">
<thead>
<tr style="background-color: #f2f2f2;">
<th style="border: 1px solid black;">
@Html.DisplayNameFor(model => model.RequestNo)
</th>
<th style="border: 1px solid black;">
@Html.DisplayNameFor(model => model.EmpID).ToString().Replace(":", "")
</th>
<th style="border: 1px solid black;">
@Html.DisplayNameFor(model => model.EmpName).ToString().Replace(":", "")
</th>
<th style="border: 1px solid black;">View Form</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr style="background-color: #f2f2f2;">
<td style="border: 1px solid black;">
@Html.DisplayFor(modelItem => item.RequestNo)
</td>
<td style="border: 1px solid black;">
@Html.DisplayFor(modelItem => item.EmpID)
</td>
<td style="border: 1px solid black;">
@Html.DisplayFor(modelItem => item.EmpName)
</td>
<td style="border: 1px solid black;">
@Html.ActionLink("View Form", "Details", new { id = item.RequestNo })
</td>
</tr>
}
</tbody>
</table>
</div>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<script>
$(document).ready(function () {
$('#dtbl').DataTable({
"scrollX": true,
"pageLength": 10,
dom: 'Bfrtip',
initComplete: function () {
// Remove export buttons
$('.buttons-excel, .buttons-pdf, .buttons-print, .buttons-csv, .buttons-copy').remove();
}
});
});