Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
BRH 48
#DOTNET 34
#ASP.NET 29
jQuery 22
ASP.NET 20
.NET 20
WPF 9
jquery interview questions 9
jquery faq 8
ASP.NET4 8

Archive · View All
February 2011 10
September 2011 4
August 2011 4
July 2011 4
May 2011 4
April 2011 4
March 2011 4
October 2011 4
June 2011 4
January 2011 4

Client Side Sorting in ASP.NET Grid View using JQuery

Jan 1 2011 12:00PM by Hima   

JQuery has become quite popular on the web due to its client side nature of doing anything and everything. In this article I would like to demonstrate implementation of client side sorting for ASP.NET Grid View using JQuery.

The plug-in supports only client side sorting based on JavaScript algorithm.  Table Sorter is required to implement the scenario. The Table Sorter Plug-in can be found here . The Plug-in sorts HTML Table.  We need to Download the latest version of the jQuery from here

Step1: Include necessary js Files

Include Table Sorter Plug-in and jQery Plug-in , jQuery Plugin is required for loading tablesorter. So we need to include jQuery  1.3.2.min.js  before table sorter plugin inclusion.

 <head runat="server"> 
<script src="../scripts/jquery-1.3.2.min.js" type="text/javascript">
</script> <script src="../Scripts/jquery.tablesorter.min.js" type="text/javascript">
</script>
 </head> 

It is imagined that you already have code for grid binding form Database or LINQ or XML or whatever it may be

In my case I am getting data from the Database . 

if (dsParamValues.Tables.Count > 0 && dsParamValues.Tables[0].Rows.Count > 0) 
  { 
  grdResults.DataSource = dsParamValues; grdResults.DataBind(); 
  } 
 

Step2: Render Grid <Thead> and <Tbody> tags

Table Sorter needs the tags <Thead> and <Tbody> for the sorting . So we need to have the GridView control renders these tages. GridView will be converted as HTML table , but <thead> <tbody> are not rendered by defualt.

We can explicitly make this using the following code.
if (grdResults.Rows.Count > 0) 
{ 
grdResults.UseAccessibleHeader = true;
grdResults.HeaderRow.TableSection = TableRowSection.TableHeader; 
}

Step3: Calling Table Sorter Plug-in 

 
  $(document).ready(function () 
  {$("#grdResults").tablesorter();}); 

We can either use the same code in the Code behind as

 
ScriptManager.RegisterStartupScript(this, GetType(), "SortGrid",string.Format("$(function(){{$('#{0}').tablesorter(); }});",grdResults.ClientID), true);

That’s it . Now run the page we will be able to sort the columns on clicking the header. And it’s much faster.

Tip: Use AJAX to remove post backs since if the buttons because post back, grid will return to initial state since the sorting was only done on the client side.

As this plug-in supports only client side sorting based on JavaScript algorithm, all the events which are bound to the grid are lost when fresh page is sent by web server. Unlike ASP.NET model, events will not persist in client side programming. So we need to re-bind the client side events after post back.

The code snippet for the rebinding can be as follows

 
<script type="text/javascript"> $(function() { initializer(); }); < 
var prmInstance = Sys.WebForms.PageRequestManager.getInstance();
prmInstance.add_endRequest(function()
{ //rebinding events initializer(); 
}); 

function initializer() { $("table[id$='grdResults']").tablesorter(); } 
</script> 

Hope it is clear about client side sorting using jQuery. Let me know if you have any questions

Happy Beyondrelationaling

Tags: BRH, .NET, #DOTNET, ASP.NET4, #ASP.NET, ASP.NET, .NET4, sorting, Clientside Sorting, jQuery,


Hima
31 · 6% · 1776
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

4  Comments  

  • thanx for the article 1 - Download link of table sorter script is not working, please correct that. 2 - I have set the required properties and grid is displayed with some rows but header columns are not click able, what i am missing?

    commented on Jun 15 2011 2:26AM
    Shafaqat Ali
    1446 · 0% · 14
  • Did you use the code to render tHead and tBody for the GridView. Look at the view Source if your table has these

    commented on Jul 5 2011 7:01AM
    Hima
    31 · 6% · 1776
  • Hi Hima,

    In this example, if i have pagging then if u do sorting ,it sorts paging also. how we can avoid it.

    commented on Sep 20 2011 8:17AM
    ramarao
    2903 · 0% · 2
  • HIma,

    Is there a way you can post / upload a sample solutioin.. I cannot make this work as i am getting this error..

    Line: 868 Error: Sys.WebForms.PageRequestManagerServerErrorException: The GridView 'gridComponents' fired event Sorting which wasn't handled.

    Here are few pointers,

    • I have my grid inside an update panel
    • I Left AllowSorting=true in the grid arrtibute
    • I removed "OnSorting" attribute from the grid as this may lead to server post back for sorting.

    For rest everything, I followed your steps and getting this error when I click the column header. Please help me.

    John

    commented on Feb 23 2012 11:29PM
    mrjonie
    2713 · 0% · 3

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]