Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote a simple example that should illustrate the idea.</p> <p>Start by writing a generic handler for handling data on the server side (<code>Data.ashx</code> but this could be a web page, web service, anything server side script capable of returning JSON formated data):</p> <pre><code>public class Data : IHttpHandler { public void ProcessRequest(HttpContext context) { // Those parameters are sent by the plugin var iDisplayLength = int.Parse(context.Request["iDisplayLength"]); var iDisplayStart = int.Parse(context.Request["iDisplayStart"]); var iSortCol = int.Parse(context.Request["iSortCol_0"]); var iSortDir = context.Request["sSortDir_0"]; // Fetch the data from a repository (in my case in-memory) var persons = Person.GetPersons(); // Define an order function based on the iSortCol parameter Func&lt;Person, object&gt; order = p =&gt; { if (iSortCol == 0) { return p.Id; } return p.Name; }; // Define the order direction based on the iSortDir parameter if ("desc" == iSortDir) { persons = persons.OrderByDescending(order); } else { persons = persons.OrderBy(order); } // prepare an anonymous object for JSON serialization var result = new { iTotalRecords = persons.Count(), iTotalDisplayRecords = persons.Count(), aaData = persons .Select(p =&gt; new[] { p.Id.ToString(), p.Name }) .Skip(iDisplayStart) .Take(iDisplayLength) }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(result); context.Response.ContentType = "application/json"; context.Response.Write(json); } public bool IsReusable { get { return false; } } } public class Person { public int Id { get; set; } public string Name { get; set; } public static IEnumerable&lt;Person&gt; GetPersons() { for (int i = 0; i &lt; 57; i++) { yield return new Person { Id = i, Name = "name " + i }; } } } </code></pre> <p>And then a WebForm:</p> <pre><code>&lt;%@ Page Title="Home Page" Language="C#" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt; &lt;head id="Head1" runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="/styles/demo_table.css" /&gt; &lt;script type="text/javascript" src="/scripts/jquery-1.4.1.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="/scripts/jquery.dataTables.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function () { $('#example').dataTable({ 'bProcessing': true, 'bServerSide': true, 'sAjaxSource': '/data.ashx' }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="Form1" runat="server"&gt; &lt;table cellpadding="0" cellspacing="0" border="0" class="display" id="example"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;ID&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td colspan="5" class="dataTables_empty"&gt;Loading data from server&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The example is oversimplified but I hope it will illustrate the basics on how to get stared.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload