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

RadGrid multiple filter from Javascript

1 Answer 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
satish begum
Top achievements
Rank 1
satish begum asked on 31 Jul 2014, 12:30 PM
Im trying to filter Grid with Javascript

<telerik:radgrid ID="RadGrid1" runat="server" AutoGenerateColumns="True"  AllowSorting="True" ShowGroupPanel="True" GroupingEnabled="True" DataSourceID="SqlDataSource1"                 OnExcelMLWorkBookCreated="RadGrid1_ExcelMLWorkBookCreated" OnGroupsChanging="RadGrid1_OnGroupsChanging"                  AllowFilteringByColumn="true">
                <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
                <ClientSettings ReorderColumnsOnClient="false" AllowDragToGroup="True" AllowColumnsReorder="false">
                    <Selecting AllowRowSelect="false"></Selecting>
                    <Resizing AllowRowResize="False" AllowColumnResize="False" EnableRealTimeResize="True"
                        ResizeGridOnColumnResize="False"></Resizing>
                </ClientSettings>
                <GroupingSettings ShowUnGroupButton="true"></GroupingSettings>
</telerik:radgrid>

Here is Javascript
var grid  = $find('ctl00_MainContent_RadGrid1');
var master = $find('ctl00_MainContent_RadGrid1').get_masterTableView();
master.filter("Type", 'SWITCHED', "EqualTo");
master.filter("Resource", 'POWER', "EqualTo");

Only the second filter applies but not first.

Please suggest  how to apply both, and it would be better suggest n filters

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 05 Aug 2014, 09:03 AM
Hello,

From the provided code it seems that the RadGrid is using server-side binding. In this scenario the filtering would also be done on the server. The fitler() function fires a command that applies the specified filter for a column in the grid. Because this triggers a postback only one of the filters is applied. This is expected behavior.

In order to implement the functionality you could fire a custom command and pass the information for filtering as an argument:

function filterGrid() {
    var grid = $find("<%= RadGrid1.ClientID %>");
    var masterTable = grid.get_masterTableView();

    masterTable.fireCommand("CustomFilter", "Type:SWITCHED?EqualTo,Resource:POWER?EqualTo");
     
}

Then you would need to add handler for the OnItemCommand event and implement the filtering. You would need to parse the string that is passed and modify the RadGrid FilterExpression accordingly.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName=="CustomFilter")
    {
        string filteringData = e.CommandArgument.ToString();
         
        // parse string and set the FilterExpression
    }
}

if you would like additional information on modifying the FilterExpression manually you would find the following article interesting:
I hope the information would prove helpful.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
satish begum
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or