在服务器端 jquery 数据 table 的列上使用 if else 与 ASP.NET Web 服务
Using if else on columns in server side jquery data table with ASP.NET Web Service
寻找答案已经有一段时间了。
问题是我总是使用 ajax 请求来填充我的数据 table 并且可以根据列值轻松应用 if else 条件,但这种做法适用于小于 50,000 的数据。今天我碰巧在一个有更多行的更大的数据集上使用数据table,所以我使用了这个代码:
$("#example").DataTable({
columns: [
{'data': 'employer_id' },
{ 'data': 'intern_id' }
],
sAjaxSource: '../EmployeeService.asmx/GetEmployees',
sServerMethod: 'post'
})
});
使用 Web 服务获取数据和用于服务器端处理的存储过程,效果非常好。现在,我的问题是,如何在此 table 上使用 if else,例如,如果我在 column1 中有 "abc",我想在数据 table 中显示 "ABC"。
帮助!
columnDefs: [ {
targets: 0,
render: function ( data, type, row ) {
if (data == 0) {
return "zero";
}
else
return "non zero";
}
},
{
targets: 1,
render: function (data, type, row) {
if (data == 0) {
return " intern zero";
}
else
return "intern non zero";
}
}]
这已经完成了工作。
寻找答案已经有一段时间了。 问题是我总是使用 ajax 请求来填充我的数据 table 并且可以根据列值轻松应用 if else 条件,但这种做法适用于小于 50,000 的数据。今天我碰巧在一个有更多行的更大的数据集上使用数据table,所以我使用了这个代码:
$("#example").DataTable({
columns: [
{'data': 'employer_id' },
{ 'data': 'intern_id' }
],
sAjaxSource: '../EmployeeService.asmx/GetEmployees',
sServerMethod: 'post'
})
});
使用 Web 服务获取数据和用于服务器端处理的存储过程,效果非常好。现在,我的问题是,如何在此 table 上使用 if else,例如,如果我在 column1 中有 "abc",我想在数据 table 中显示 "ABC"。 帮助!
columnDefs: [ {
targets: 0,
render: function ( data, type, row ) {
if (data == 0) {
return "zero";
}
else
return "non zero";
}
},
{
targets: 1,
render: function (data, type, row) {
if (data == 0) {
return " intern zero";
}
else
return "intern non zero";
}
}]
这已经完成了工作。