Wijmo's more elegant jQuery UI parts set: processing Wijmo GridView data operations at runtime

original
2014/06/11 12:01
Reading number 232

C1GridView has many built-in functions, such as sort filter paging as well as grouping

 image

For developers, these are very useful functions, because they can save a lot of time to implement these capabilities through code.
In any case, developers do not have to bind it to a data source at design time. In fact, in most cases, data is bound dynamically.

This article discusses how to implement sorting, filtering and grouping when C1GridView dynamically binds data.

binding C1GridView

C1GridView can be bound to an ADO NET data sources, such as DataSet, DataTable, etc. For this example, we bind the grid to the "Customers" table of the C1NWind.mdb database file.

 


  
  
  1. public  DataSet BindGrid() 
  2.  
  3.  
  4.     OleDbConnection con =  new  OleDbConnection( "provider=Microsoft.Jet.Oledb.4.0; Data Source="  + Server. MapPath( "~/App_Data/C1NWind.mdb" ));  
  5.  
  6.     OleDbDataAdapter da;  
  7.  
  8.     DataSet ds =  new  DataSet();  
  9.  
  10.     da =  new  OleDbDataAdapter( "Select * from Customers" , con);  
  11.  
  12.     da. Fill(ds);  
  13.  
  14.      return  ds;  
  15.  
  16.  
  17. protected   void  Page_Load( object  sender, EventArgs e) 
  18.  
  19.  
  20.      if  (!IsPostBack) 
  21.  
  22.     { 
  23.  
  24.         C1GridView1.DataSource = BindGrid();  
  25.  
  26.         C1GridView1.DataBind();  
  27.  
  28.     } 
  29.  

 

handle C1GridView event

sort
To achieve sorting, we need to process Sorting as well as Sorted event. Grid will be rebound in the Sorted event.

 


  
  
  1. protected   void  C1GridView1_Sorting( object  sender, C1.Web. Wijmo.Controls.C1GridView.C1GridViewSortEventArgs e) 
  2.  
  3.  
  4.  
  5. //Processing Sorting  
  6.  
  7. protected   void  C1GridView1_Sorted( object  sender, EventArgs e) 
  8.  
  9.  
  10.     C1GridView1.DataSource = BindGrid();  
  11.  
  12.     C1GridView1.DataBind();  
  13.  

 

filter
The code for processing filtering and the logic for processing sorting are identical. We need to deal with Filtering as well as Filtered event.

 


  
  
  1. protected   void  C1GridView1_Filtering( object  sender, C1.Web. Wijmo.Controls.C1GridView.C1GridViewFilterEventArgs e) 
  2.  
  3.  
  4.  
  5. //Processing Filtering  
  6.  
  7. protected   void  C1GridView1_Filtered( object  sender, EventArgs e) 
  8.  
  9.  
  10.     C1GridView1.DataSource = BindGrid();  
  11.  
  12.     C1GridView1.DataBind();  
  13.  

 

paging
The logic of paging is slightly different from that of sorting and filtering. We just need to deal with Paging event. First set the PageIndex of G1GridView to NewPageIndex, and then rebind the grid as we did before.

 


  
  
  1. protected   void  C1GridView1_PageIndexChanging( object  sender, C1.Web. Wijmo.Controls.C1GridView.C1GridViewPageEventArgs e) 
  2.  
  3.  
  4.     C1GridView1.PageIndex = e. NewPageIndex;  
  5.  
  6.     C1GridView1.DataSource = BindGrid();  
  7.  
  8.     C1GridView1.DataBind();  
  9.  

 

grouping
To group the C1GridView, you need to set the AllowColMoving and ShowGroupArea properties to true. We also need to process the ColumnGrouped and ColumnUngrouped events, and leave the ColumnUngrouped event blank. However, in the ColumnGrouped event, we must rebind the grid. The difference is that this time we need to add a parameter, which is the HeaderText of the column being dragged or grouped. This parameter is used to sort by this column first, and then apply grouping to ensure that no duplicate grouping is created.

 


  
  
  1. //Processing Column Grouping  
  2.  
  3. protected   void  C1GridView1_ColumnGrouped( object  sender,   C1.Web. Wijmo.Controls.C1GridView.C1GridViewColumnGroupedEventArgs e) 
  4.  
  5.  
  6.     C1GridView1.DataSource = BindGrid(e.Drag.HeaderText);  
  7.  
  8.     C1GridView1.DataBind();  
  9.  
  10.  
  11. //Processing Column UnGrouping  
  12.  
  13. protected   void  C1GridView1_ColumnUngrouped( object  sender, C1.Web. Wijmo.Controls.C1GridView.C1GridViewColumnUngroupedEventArgs e) 
  14.  
  15.  

  image

Download sample

 

Wijmo download, please enter Studio for ASP.NET Wijmo 2012 v1 was officially released (updated on March 22, 2012)!

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
zero Collection
zero fabulous
 Back to top
Top