带有WCFrest服务的jQuery数据表 [英] jQuery Datatables with WCFrest service
问题描述
我正在尝试使用连接到WCF Rest Service的jQuery Datatables(多个数据表)来获取数据。使用存储过程我是绑定值。
我的代码如下:
I'm trying to use jQuery Datatables(multiple datatables) that connects to WCF Rest Service to get data.Using stored procedures I am binding values.
My code as follows:
//SectionII DataTable
function DataTable_Report() {
CommonValue();
$.ajax({
url: "../Handler.ashx",
type: "POST",
datatype: 'json',
cache: false,
data: { "fromDate": fromDate, "toDate": toDate, "OfficerId": OfficerId, "stateShortName": stateShortName, "request": "SectionIIGetRequest" },
beforeSend: function () {
$(".SectionII-datatables").html("<img src='../images/ajax-loader.gif' alt='Loading...' style='width:220px;height:19px;margin:35px auto 0 auto;display:block' class='dataTable_loader'/>");
},
success: function (data) {
var dt = $.parseJSON(data);
if (dt.Values == null)
$(".SectionII-datatables").html("<h1 style='color:red;text-align:center;margin:2% auto;' class='dataTable_loader'>No Records to display</h1>");
if (dt.ResponseCode == "1001") {
$(".SectionII-datatables dataTable_loader").remove();
$('.SectionII-datatables').html('<table width="100%" cellpadding="0" cellspacing="0" border="0" class="ReportHeader" id="SectionII-table"></table>');
$('#table_id').dataTable();
Values = dt.Values;
table = $('table#table13').dataTable({
"bJQueryUI": false,
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"bPaginate": false,
"bFilter": false,
"bInfo": false,
"bSearch": false,
"aaSorting": [],
"aaData": Values,
"aoColumns": [
{ "sTitle": "", "mData": "Code", "mRender": fnDefaultValue },
{ "sTitle": "", "mData": "Channel", "mRender": fnDefaultValue },
{ "sTitle": "", "mData": "_Amount", "mRender": fnDefaultValue },
{ "sTitle": "", "mData": "Nos", "mRender": fnDefaultValue }
]
});
}
else if (dt.ResponseCode == "2001") { Values = ""; }
}
});
var fnDefaultValue = function (value) { return value; }
}
和我的服务代码如下:
and my service code as follows:
public WebResponseForSelect<ReportEntity> sectionII(string fromDate, string toDate, int officerid, string stateshortname)
{
Parameters();
prm[0].Value = fromDate;
prm[1].Value = toDate;
if (officerid.Equals(0))
prm[2].Value = null;
else
prm[2].Value = officerid;
if (stateshortname.Equals(string.Empty))
prm[3].Value = null;
else
prm[3].Value = stateshortname;
dt = dbcon.ExecuteSP("getNMLSsectionII", prm);
List<NMLSReportEntity> listSectionII = (from e in dt.AsEnumerable()
select new NMLSReportEntity
{
NMLSCode = e.Field<string>("NMLSCode"),
Channel = e.Field<string>("Channel"),
_Amount = e.Field<string>("totalAmt"),
No_Of_ = e.Field<string>("Nos")
}).ToList<NMLSReportEntity>();
if (listSectionII.Count > 0)
return new WebResponseForSelect<NMLSReportEntity>() { ResponseCode = "1001", ResponseMessage = "Successfully retrieved", Values = listSectionII };
else
return new WebResponseForSelect<NMLSReportEntity>() { ResponseCode = "2001", ResponseMessage = "No Records Found" };
}
对于每个数据表绑定,我调用单独的调用在服务中。我有一个数据包,其中包含300多条记录。有时它会显示。有时它不会......需要更多的时间来加载。如何提高性能?请帮助我...它的紧急..很快就会:(
For each datatable binding,I am calling seperate call in service.I have one datatable which containd more than 300 records.Sometimes it will show.and sometimes it wont..it will take more time to load.How to increase performance?Please help me...Its urgent..Reply soon :(
推荐答案
.ajax({
url:../ Handler.ashx,
类型:POST,
数据类型:'json',
cache:false,
data:{fromDate:fromDate,toDate:toDate,OfficerId:OfficerId,stateShortName:stateShortName,request :SectionIIGetRequest},
beforeSend:function(){
.ajax({ url: "../Handler.ashx", type: "POST", datatype: 'json', cache: false, data: { "fromDate": fromDate, "toDate": toDate, "OfficerId": OfficerId, "stateShortName": stateShortName, "request": "SectionIIGetRequest" }, beforeSend: function () {
(。SectionII-datatables)。html(< img src ='.. / images / ajax-loader.gif'alt ='正在加载''style ='width:220px; height:19px; margin:35px auto 0 auto; display:block'class ='dataTable_loader'/>);
},
成功:功能(数据) {
var dt =
(".SectionII-datatables").html("<img src='../images/ajax-loader.gif' alt='Loading...' style='width:220px;height:19px;margin:35px auto 0 auto;display:block' class='dataTable_loader'/>"); }, success: function (data) { var dt =
.parseJSON(data);
if(dt.Values == null)
.parseJSON(data); if (dt.Values == null)
这篇关于带有WCFrest服务的jQuery数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!