如何使用ajax调用带有参数的webservice来突出显示数据表中的搜索? [英] How to highlight search in datatable using ajax call to webservice with parameter?

查看:58
本文介绍了如何使用ajax调用带有参数的webservice来突出显示数据表中的搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码没问题。但我想突出显示数据表中的搜索词但无法做到。我在datatable中尝试过ajax属性但是出错了。



我在哪里以及如何做到这一点?



使用数据库上传完整代码:https://drive.google.com/open?id = 0BySGGgZO1jMVQVNDMmx1UWF1MlE



我尝试过:



$(凭证).ready(功能(){





$('#jobSearchButton')。click(function(){



$(#datatable)。dataTable()。api()。destroy( );



var empJob = $('#jobTitleTextBox')。val();



$ .ajax({

url:'EmployeeService.asmx / GetEmployees',

data:{jobTitle:empJob},

dataType:'json ',

方法:'post',

成功:函数(数据){

$('#datatable')。dataTable({

分页:true,

sort:true,

搜索:true,

scrollY:200,

数据:数据,

栏:[

{'数据':'Id'},

{'数据':'FirstName'},

{'data':'LastName'},

{'data':'Gender'},

{'data':'JobTitle '},

{

'数据':'网站',

'可排序':false,

'searchable':false,

'grave':function(webSite){

if(!webSite){

返回'N / A';

}

else {

返回''

+ webSite.substr(0,10)+'...'+'
';

}

}

},

{

'数据':'薪水',

'渲染':功能(工资){

返回$+工资;

}

},

{

'数据':'HireDate',

render':function(jsonDate){

var date = new Date(parseInt(jsonDate.substr(6)));

var month = date.getMonth()+ 1;

返回月份+/+ date.getDate()+/+ date.getFullYear();

}

}

]

});

}





});



});

});

the code is okay. But i want to highlight search word in datatable but could not do it. i tried ajax property in datatable but got error.

where and how can i do it?

Full code is uploaded there with database: https://drive.google.com/open?id=0BySGGgZO1jMVQVNDMmx1UWF1MlE

What I have tried:

$(document).ready(function () {


$('#jobSearchButton').click(function () {

$("#datatable").dataTable().api().destroy();

var empJob = $('#jobTitleTextBox').val();

$.ajax({
url: 'EmployeeService.asmx/GetEmployees',
data: { jobTitle: empJob },
dataType: 'json',
method: 'post',
success: function (data) {
$('#datatable').dataTable({
paging: true,
sort: true,
searching: true,
scrollY: 200,
data: data,
columns: [
{ 'data': 'Id' },
{ 'data': 'FirstName' },
{ 'data': 'LastName' },
{ 'data': 'Gender' },
{ 'data': 'JobTitle' },
{
'data': 'WebSite',
'sortable': false,
'searchable': false,
'render': function (webSite) {
if (!webSite) {
return 'N/A';
}
else {
return ''
+ webSite.substr(0, 10) + '...' + '
';
}
}
},
{
'data': 'Salary',
'render': function (salary) {
return "$" + salary;
}
},
{
'data': 'HireDate',
'render': function (jsonDate) {
var date = new Date(parseInt(jsonDate.substr(6)));
var month = date.getMonth() + 1;
return month + "/" + date.getDate() + "/" + date.getFullYear();
}
}
]
});
}


});

});
});

推荐答案

(document).ready(function(){




(document).ready(function () {



('#jobSearchButton' ).click(function(){


('#jobSearchButton').click(function () {


(#datatable)。dataTable()。api()。destroy();



var empJob =
("#datatable").dataTable().api().destroy();

var empJob =


这篇关于如何使用ajax调用带有参数的webservice来突出显示数据表中的搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆