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

Pipe( | ) Symbol Filtering

1 Answer 77 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Atchyut Bandaru
Top achievements
Rank 1
Atchyut Bandaru asked on 02 Dec 2010, 08:55 AM
I using teleric control in my proejct. In teleric grid when I am entering the (|) pipe symbal for filtering then I am getting error, Please can you provide me solution for that. 

Regards,

Atchyut

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 07 Dec 2010, 10:08 AM
Hi Atchyut,

The pipe symbol is used in RadGrid for delimiting portions of the command argument when sending commands to the server. You need to escape it. To do that, you need to use RadGrid's client-side OnCommand event to encode the filter value, as well as the server-side OnItemCommand to decode it:

<telerik:RadGrid ID="RadGrid1" runat="server" Width="1000px"
    OnNeedDataSource="RadGrid1_NeedDataSource"
    AllowFilteringByColumn="true"
    OnItemCommand="RadGrid1_ItemCommand">
    <ClientSettings>
        <ClientEvents OnCommand="gridCommand" />
    </ClientSettings>
</telerik:RadGrid>

function gridCommand(sender, args)
{
    if (args.get_commandName() == "Filter")
    {
        if (!args.get_tableView()._performFilter)
        {
            args.set_cancel(true);
 
            var commandArgs = args.get_commandArgument().split("|");
            var fieldName = commandArgs[0];
            var filterFunction = commandArgs[commandArgs.length - 1];
 
            commandArgs.splice(0, 1);
            commandArgs.splice(commandArgs.length - 1, 1);
            var filterValue = commandArgs.join("|");
 
            args.get_tableView()._performFilter = true;
            args.get_tableView().filter(fieldName, escape(filterValue), filterFunction);
        }
    }
}

private bool fireFilterCommand = false;
 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        if (!fireFilterCommand)
        {
            //if this is the first firing of the Filter command, cancel it,
            // so that we can decode the filter value
            e.Canceled = true;
 
            Pair filterPair = e.CommandArgument as Pair;
            string dataField = HttpUtility.UrlDecode(filterPair.Second.ToString());
            string filterFunc = filterPair.First.ToString();
            string filterValue = e.Item.OwnerTableView.GetColumn(dataField).CurrentFilterValue;
 
            //find the filter textbox in the filtering item and set its value
            //to the decoded filter value
            Control filterInput = (e.Item as GridFilteringItem)[dataField].Controls[0];
            if (filterInput is TextBox)
            {
                ((TextBox)filterInput).Text = HttpUtility.UrlDecode(filterValue);
            }
 
            //allow firing of Filter command and fire it from the filtering item
            fireFilterCommand = true;
            e.Item.FireCommandEvent(RadGrid.FilterCommandName, new Pair(filterFunc, dataField));
        }
        else
        {
            fireFilterCommand = false;
        }
    }
}

Attaching a test page to demonstrate.

Veli
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Filter
Asked by
Atchyut Bandaru
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or