Intersoft WebGrid Documentation
How-to: Add and remove Filtered Column programmatically
See Also Send comments on this topic.

Glossary Item Box

Filtering feature can be added or removed programmatically.

In this topic, you will learn how to programmatically add and remove filter in WebGrid.

To add filter programmatically in WebGrid

Server Side

  1. Drag a standard button to your WebForm.
  2. On ButtonClick event handler, put the following code:

    C# Copy ImageCopy Code
    private void Button1_Click(object sender, System.EventArgs e)
    {
       WebGridFilter fltr = new WebGridFilter("ContactName", ColumnFilterType.Like, "Ana");
       WebGrid1.RootTable.FilteredColumns.Add(fltr);
    }
    

  3. Run the Project.

Client Side

  1. Drag a HTML button to your form.
  2. Create AddFilter() functions in client-side:

    JavaScript Copy ImageCopy Code
    function AddFilter()
    {
       var grid = ISGetObject("WebGrid1");
       var newFilter = new WebGridFilter();
       newFilter.ColumnMember = "ContactName";
       newFilter.FilterType = "Like";
       newFilter.FilterText = "Ana";                
       grid.RootTable.FilteredColumns.Add(newFilter);                            
       grid.RootTable.UpdateUI();
       grid.Refresh();
    }
    

  3. Invoke AddFilter() function in <INPUT type="button" value="Add Filter" onclick="AddFilter()">
  4. Run the Project.

To remove filter programmatically in WebGrid

Server Side

  1. Drag a standard button to your WebForm.
  2. On ButtonClick event handler, put the following code:

    C# Copy ImageCopy Code
    private void Button2_Click(object sender, System.EventArgs e)
    {
      WebGrid1.RootTable.FilteredColumns[0].FilterType = ColumnFilterType.NotSet;
      WebGrid1.RootTable.FilteredColumns[0].FilterText = "";
    }
    

  3. Run the Project.

Client Side

  1. Drag a HTML button to your form.
  2. Add RemoveFilter() functions in client-side:

    JavaScript Copy ImageCopy Code
    function RemoveFilter()
    {
      var grid = ISGetObject("WebGrid1");                                    
      grid.RootTable.FilteredColumns.Remove(grid.RootTable.FilteredColumns[0], true);                  
      grid.RootTable.FilteredColumns[0].FilterType = "";
      grid.RootTable.FilteredColumns[0].FilterText = "";                             
      grid.RootTable.UpdateUI();
      grid.Refresh();
    }
    

  3. Call RemoveFilter() function in <INPUT type="button" value="Remove Filter" onclick="RemoveFilter()">.
  4. Run the Project.

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.