在我的代码中,我使用Jquery数据表的fnFilter函数来搜索数据。 在某些情况下,它搜索完美但在某些情况下不是。 如果我试图搜索代码=" BS"它会完美搜索。 但是当我尝试使用代码搜索=" AL"它将显示所有记录。这是不正确的。 这是我的数据表搜索选项代码。
$("div.dataTables_filter input").bind('keypress', function (e) {
var searchText = $(this).val().trim();
if (e.which == 13) {
$("#search-error-text").remove();
if (searchText.length > 0) {
var value = searchText;
oTable.fnFilter(value);
$("div.dataTables_filter input").val(searchText);
}
else {
var errorMessage = "Please Enter Data!";
$("div.dataTables_filter input").before("<span id='search-error-text' class='error-text'>" + errorMessage + "</span>");
return;
}
}
else {
return;
}
});
$("div.dataTables_filter #grid-search-button").click(function () {
$("#search-error-text").remove();
var searchText = $("div.dataTables_filter input").val().trim();
if (searchText.length > 0) {
var value = searchText;
oTable.fnFilter(value);
$("div.dataTables_filter input").val(searchText);
}
else {
var errorMessage = "Please Enter Data!";
$("div.dataTables_filter input").before("<span id='search-error-text' class='error-text'>" + errorMessage + "</span>");
return false;
}
});
表格下方的HTML代码。
<div class="table-responsive">
<table id="datatable-sale" class="datatable">
<thead>
<tr>
<th class="table_heading table-head ">
Code
</th>
<th class="table_heading table-head">
Description
</th>
<th class="table_heading table-head">
Type
</th>
<th class="table_heading table-head cursorDefault">
Edit
</th>
<th class="table_heading table-head cursorDefault">
Status
</th>
<th class="table_heading table-head cursorDefault">
Delete
</th>
</tr>
</thead>
<tbody class="table-head">
@foreach (var item in ViewData["sale"] as IEnumerable<Sales_lut>)
{
<tr>
<td class="table_heading text-left table-head-maintenance Width-10">
@item.code
</td>
<td class="table_heading text-left">
@item.descrip
</td>
<td class="table_heading text-left table-head-maintenance Width-10">
@item.type1
</td>
<td class="table_heading">
<a id="edit_sale" href="#" class=" edit action-button permission-based-access" saleidval="@item.saleid" permission-key="@Permissions.Sale.GetText()" sale-code="@item.code">
<i class="icon-pencil input-icon success" title="Edit">
</i>
</a>
</td>
<td class="table_heading permission-based-access" permission-key="@Permissions.Sale.GetText()">
@if (item.status == 0)
{
<a class="active" href="" title="Change Status" active-id="@item.saleid" sale-code="@item.code" active-code="@item.code">
<img id="active" src="@Url.Content("~/Content/Images/tick.png")" />
</a>
}
else
{
<a class="in-active" href="" title="Change Status" in-active-id="@item.saleid" sale-code="@item.code" in-active-code="@item.code">
<img id="in-active" src="@Url.Content("~/Content/Images/bullet_cross.png")" />
</a>
}
</td>
<td class="table_heading">
<a id="delete_sale" class=" deletesale delete permission-based-access" permission-key="@Permissions.Sale.GetText()" href="#" sale-code="@item.code">
<i class="icon-trash" title="delete">
</i>
</a>
</td>
</tr>
}
</tbody>
</table>
</div>
附上截图显示实际问题。编码&#34; FZ&#34;和&#34; AM&#34;不包含任何单词&#34; AL&#34;然后它也显示这个记录。这种情况发生在多个搜索选项中。我需要应用搜索整个数据,所以我不能使用单列搜索选项。我只找到一个问题,它搜索备用行意味着它只搜索网格中的奇数行。任何解决方案???