Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery DataTables server-side processing using ASP.NET WebForms
    primarykey
    data
    text
    <p><strong>Problem:</strong></p> <ul><li>jQuery DataTables server-side processing using ASP.NET WebForms.</li></ul> <p><strong>Solution:</strong></p> <ul><li>Darin Dimitrov answered the question using an example which pages and sorts, but doesn't do any searching. Here's my **basic** modification of his work to make searching work on his example:</li></ul> <pre><code>public class Data : IHttpHandler { public void ProcessRequest(HttpContext context) { // Paging parameters: var iDisplayLength = int.Parse(context.Request["iDisplayLength"]); var iDisplayStart = int.Parse(context.Request["iDisplayStart"]); // Sorting parameters var iSortCol = int.Parse(context.Request["iSortCol_0"]); var iSortDir = context.Request["sSortDir_0"]; // Search parameters var sSearch = context.Request["sSearch"]; // 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 = person =&gt; iSortCol == 0 ? (object) person.Id : person.Name; // Define the order direction based on the iSortDir parameter persons = "desc" == iSortDir ? persons.OrderByDescending(order) : persons.OrderBy(order); // prepare an anonymous object for JSON serialization var result = new { iTotalRecords = persons.Count(), iTotalDisplayRecords = persons.Count(), aaData = persons .Where(p =&gt; p.Name.Contains(sSearch)) // Search: Avoid Contains() in production .Where(p =&gt; p.Id.ToString().Contains(sSearch)) .Select(p =&gt; new[] {p.Id.ToString(), p.Name}) .Skip(iDisplayStart) // Paging .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>
    singulars
    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.
 

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