jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Problem using ASP.Net serverside pagination
Tagged: asp.net c# pagination linq
This topic contains 1 reply, has 1 voice, and was last updated by stewari 10 years, 7 months ago.
-
Author
-
Hello
I am trying to use the jQXGrid as a detail grid for a master Grid(which is a Gridview).
I checked the Chrome debugger and when I saw the XML response, it looks normal. But the result wont showup in the Grid, basically it shows up as blank.
My two webmethods which I am using is
[WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)] public static string GetJobDetail(int pagenum, int pagesize, int jobId) { pagenum++; var writer = new StringWriter(); var context = new abac_newEntities(); try { var testResultData = (from tests in context.testresults where tests.JobId == jobId orderby tests.EndTime descending select tests).Skip((pagenum - 1) * pagesize).Take(pagesize); var testRunData = ((from tests in testResultData where tests.JobId == jobId select new { TestRunID = tests.TestRunId }).Distinct()).ToList(); var testRun = (from tests in testRunData let dateTime = testResultData.Where(t => t.TestRunId == tests.TestRunID).Max(et => et.EndTime) where dateTime != null select new { TestRunId = tests.TestRunID, (testResultData.Where(st => st.TestRunId == tests.TestRunID).OrderBy(st => st.StartTime).First()).StartTime, EndTime = dateTime.Value, Status = GetTestRunStauts(testResultData.Where(st => st.TestRunId == tests.TestRunID).ToList()) ? "Pass" : "Fail" }).ToList(); var data = (from t in testRun select new { t.TestRunId, t.StartTime, t.EndTime, TotalTime = t.EndTime - t.StartTime, t.Status }).ToDataTable(); //DataTable data = ((from result in context.testresults where result.JobId == jobId select result).Skip((pagenum - 1) * pagesize).Take(pagesize)).ToDataTable(); data.WriteXml(writer, XmlWriteMode.WriteSchema, false); } finally { context.Dispose(); } return writer.ToString(); } [WebMethod] public static int GetTotalRowsCount(string args) { int jobId; int.TryParse(args, out jobId); var context = new abac_newEntities(); int count; try { count = (from result in context.testresults where result.JobId == jobId select result.Id).Count(); } finally { context.Dispose(); } return count; }
My JavaScript looks like this
function ShowDetails(imgObj) { var uid = document.getElementById(imgObj.id.replace("imgExpandCollapse", "lblUID")).innerHTML; if (imgObj.src.toLowerCase().indexOf("expand") != -1) { if (document.getElementById(imgObj.id.replace("imgExpandCollapse", "JobsGridView")) != null) $("#" + imgObj.id.replace("imgExpandCollapse", "JobsGridView")).slideToggle(); else { var newTr = document.createElement("tr"); var newTd = document.createElement("td"); var newDiv = document.createElement("div"); newTd.setAttribute("colspan", "16"); newTd.setAttribute("Style", "padding:0 0 0 0"); newDiv.setAttribute("id", imgObj.id.replace("imgExpandCollapse", "JobsGridView")); newDiv.setAttribute("style", "text-align:center"); newDiv.innerHTML = "<img src='../images/loading.gif'/>"; newTd.appendChild(newDiv); newTr.appendChild(newTd); $('#' + imgObj.id.replace("imgExpandCollapse", "grdRow")).after(newTr); var source = { datatype: "json", datafields: [ { name: 'TestRunId' }, { name: 'StartTime' }, { name: 'EndTime' }, { name: 'TotalTime' }, { name: 'Status' } ], formatdata: function (data) { return { pagenum: data.pagenum, pagesize: data.pagesize, jobId: uid } }, url: 'Default.aspx/GetJobDetail' }; var dataAdapter = new $.jqx.dataAdapter( source, { contentType: 'application/json; charset=utf-8', loadError: function (xhr, status, error) { alert(error); }, downloadComplete: function () { $.ajax({ type: "POST", url: 'Default.aspx/GetTotalRowsCount', data: "{'args': '" + uid + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { source.totalrecords = response.d; } }); } } ); var id = newDiv.id; $(format("#{0}", id)).jqxGrid({ width: "100%", source: dataAdapter, pageable: true, autoheight: true, virtualmode: true, rendergridrows: function (args) { return args.data; }, columns: [ { text: 'Test Run Id', dataField: 'TestRunId', width: 300 }, { text: 'Start Time', dataField: 'StartTime', width: 200 }, { text: 'End Time', dataField: 'EndTime', width: 200 }, { text: 'Total Time', dataField: 'Total Time', width: 180 }, { text: 'Status', dataField: 'Status', width: 80 } ] }); $("#" + newDiv.id).show(); } imgObj.src = "../images/collapse.png"; } else { if (document.getElementById(imgObj.id.replace("imgExpandCollapse", "JobsGridView")) != null) $("#" + imgObj.id.replace("imgExpandCollapse", "JobsGridView")).slideToggle(); imgObj.src = "../images/expand.png"; } };
The XML response that I receive looks something like this
<NewDataSet> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="ResultSet" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="ResultSet"> <xs:complexType> <xs:sequence> <xs:element name="TestRunId" type="xs:string" minOccurs="0" /> <xs:element name="StartTime" type="xs:dateTime" minOccurs="0" /> <xs:element name="EndTime" type="xs:dateTime" minOccurs="0" /> <xs:element name="TotalTime" type="xs:duration" minOccurs="0" /> <xs:element name="Status" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> <ResultSet> <TestRunId>d11cc4e3-2e2b-4f6b-a31a-35492c04f6c1</TestRunId> <StartTime>2014-10-14T15:15:00+05:30</StartTime> <EndTime>2014-10-14T15:15:01+05:30</EndTime> <TotalTime>PT1S</TotalTime> <Status>Fail</Status> </ResultSet> <ResultSet> <TestRunId>b842f7e3-a8b3-4a81-a05d-351d53707c59</TestRunId> <StartTime>2014-10-14T15:14:00+05:30</StartTime> <EndTime>2014-10-14T15:14:01+05:30</EndTime> <TotalTime>PT1S</TotalTime> <Status>Fail</Status> </ResultSet> <ResultSet> <TestRunId>babfd063-5f03-458d-81a0-36c5b099249d</TestRunId> <StartTime>2014-10-14T15:13:05+05:30</StartTime> <EndTime>2014-10-14T15:13:09+05:30</EndTime> <TotalTime>PT4S</TotalTime> <Status>Fail</Status> </ResultSet> <ResultSet> <TestRunId>867258b4-230e-4450-b19f-879f80f50810</TestRunId> <StartTime>2014-10-08T18:03:19+05:30</StartTime> <EndTime>2014-10-08T18:06:26+05:30</EndTime> <TotalTime>PT3M7S</TotalTime> <Status>Fail</Status> </ResultSet> </NewDataSet>
I am not sure as to what I am doing it wrong. I tried with JSON type, but it still wont show up
Any help would be great.
Thanks!
There was a problem with me passing the wrong “record” value. Its fixed now
-
AuthorPosts
You must be logged in to reply to this topic.