This is a migrated thread and some comments may be shown as answers.

[Solved] Reset Filtering to initial Filter

1 Answer 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
mike
Top achievements
Rank 1
mike asked on 13 Dec 2011, 09:31 PM
I need to know how I can get the default filter back in the grid.

I have a grid that sets the default filter as such

<% Html.Telerik().Grid<ActionAlertManagementSystem.Models.ActionAlertModel>().Name("Grid")
      .Columns(
                  columns =>
                  {
                      columns.Bound(o => o.MethodCaseId).ClientTemplate(
                              "<a href=\"../actionalert/index/<#= aa#>\"> <#= aa #> </a>"
                          );
                           columns.Bound(o => o.CreatedOn).Format("{0:MM/dd/yyyy}");
                      columns.Bound(o => o.LastModOn).Format("{0:MM/dd/yyyy}");
                      columns.Bound(o => o.WorkFLowStatus).Filterable(true);
                       
                                              
                  }
              )
              .DataBinding(
                              dataBinding =>
                              {
                                  dataBinding.Ajax().Select("_Index", "MyBusinessUnit",   new {structureId =  Model.StructureId, businessUnitId = Model.BusinessUnitId}).Enabled(true);
                              })
                              .NoRecordsTemplate("<span style='display:none' id='noRecordTemplate'>Data were not found or you may not have permission to access these particular data. If you believe you received this message in error, please contact <a href=\"mailto:gohelp@gallup.com\" title=\"Send e-mail\">gohelp@gallup.com</a>.</span>")
  .Scrollable(scrolling => scrolling.Enabled(false))
  .Sortable(sorting => sorting.Enabled(true))
  .Pageable(paging => paging.Enabled(true))
  .Filterable(filtering => filtering.Filters(filters =>
          filters.Add(o => o.WorkFLowStatus).IsEqualTo("Open")))
 
  .Footer(true)
  .ClientEvents(events => events.OnLoad("Grid_Load").OnDataBinding("Grid_Binding").OnDataBound("Grid_Bound").OnError("Grid_Error") )
  .Render();
    %>


I have a function that is called when a button is clicked to clear the filters and then refilter the grid.
function Reset() {
 
    var _searchTerm = $("#txtCaseId").val('');
    var _grid = $("#Grid").data('tGrid');
   ClearGridFilterInputs();
   _grid.filter("WorkFlowStatus~eq~'Open'");
 
}
 
 
function ClearGridFilterInputs() {
    $('#Grid .t-filter-options')
            .find('input[type="text"], select')
                        .val('');
    $('#Grid .t-clear-button').click();
    $('#Grid .t-filter-button').click();
}


The grid shows filtered but the Filter Box is empty. Is there any way to get that Fitler box populated for the column I'm refiltering to?

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 15 Dec 2011, 06:20 PM
Hi Mike,

To achieve it you can set the filter inputs like this (check the snippet) after you filter the Grid using the client API

function Reset() {
    var _searchTerm = $("#txtCaseId").val('');
    var _grid = $("#Grid").data('tGrid');
   ClearGridFilterInputs();
   _grid.filter("WorkFlowStatus~eq~'Open'");
   $('.t-filter-operator').first().val('eq');
   $('.t-formatted-value').first().html('Open');
}
I hope this helps. If this is not what you are trying to achieve please provide more details or a screenshot describing your needs.

Greetings,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
mike
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or