【发布时间】:2016-02-11 09:59:12
【问题描述】:
我在 SO 上看到了许多线程,它们展示了如何在输入时实现搜索(默认行为是每次按键后搜索),但由于某种原因,当我对 DataTables 代码进行服务器端处理时,会忽略默认行为并返回。任何人都知道如何在用户按下回车后开始搜索?
这就是我现在得到的,搜索部分代码被完全忽略(searchDelay 也没有效果——来自 DataTables 文档)
var adminRoles;
$(document).ready(function () {
adminRoles = $('#adminRoles').dataTable({
info: true,
order: [[0, 'asc']],
processing: true,
serverSide: true,
searchDelay: 500, //does't work
ajax: {
url: "@Url.Action("GetRoles","Admin")",
type: "POST"
},
columnDefs: [
{ data: "Name", targets: 0 },
{ data: "KeyName", targets: 1 },
{
data: "Id",
className: "text-center editDetail clickable",
render: function (data, type, row) {
return '<button class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil text-primary" /></button>';
},
sortable: false,
searchable: false,
targets: 2
}
],
language: {
url: '@Url.Content(@Resource.js_DataTables_Language)'
}
}).api();
$('#adminRoles_filter input').unbind().bind('keypress', function (e) {
if (e.which == 13) {
alert('You pressed enter!'); //doesn't get hit
//adminRoles.search(this.value).draw();
}
return;
});
});
【问题讨论】:
标签: jquery asp.net-mvc datatables