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

Grid filter

6 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Seban
Top achievements
Rank 1
Seban asked on 22 Jan 2014, 12:31 PM
Sir,
 I have a grid , in in itemcreated event
i put the below code
this.rgVessel.MasterTableView.FilterExpression = "([SELECTED] = True' OR" + this.rgVessel.MasterTableView.FilterExpression;

but
([SELECTED] = True'  is not working , only the current filter is working.
but the filterexperssion contains the two column filter.
please help immediately.

by,

Seban

6 Answers, 1 is accepted

Sort by
0
Accepted
Lukas
Top achievements
Rank 1
answered on 22 Jan 2014, 12:41 PM
Hello Jessy,

Try
this.rgVessel.MasterTableView.FilterExpression = "([SELECTED] = 'True' OR " + this.rgVessel.MasterTableView.FilterExpression;

I am not a professional like the helpers here but i think you missed the ' before True and a space after the OR

Kind regards 
Lukas
0
Seban
Top achievements
Rank 1
answered on 23 Jan 2014, 06:52 AM
Sir,

Thanks to your replay , but its not working correctly.

My grid contains 3 columns   ID,NAME and SELECTED(boolean)

in pageload i am setting the
  rgVessel.MasterTableView.FilterExpression = "([SELECTED] = 'True'  )";

  ViewState["PlanVesselExpression"] = rgVessel.MasterTableView.FilterExpression;

 in

itemCommand event is below


 protected void rgVessel_ItemCommand(object sender, GridCommandEventArgs e)
        {
            try
            {
             

                if (e.CommandName =="Filter")
                {
                    //string var = rgVessel.MasterTableView.FilterExpression;

                  
                    if (ViewState["PlanVesselExpression"] != null)
                    {
                        if (!Convert.ToString(ViewState["PlanVesselExpression"]).Contains("([SELECTED] = 'True' )"))
                        {
                            this.rgVessel.MasterTableView.FilterExpression = "([SELECTED] = 'True' ) OR" + Convert.ToString(ViewState["PlanVesselExpression"]); ;

                        }
                        this.rgVessel.MasterTableView.FilterExpression = Convert.ToString(ViewState["PlanVesselExpression"]);
                    }
                    this.rgVessel.MasterTableView.FilterExpression = Convert.ToString(ViewState["PlanVesselExpression"]);
                    this.fnCkeckVesselSelectedItem();
                    this.rgVessel.DataSource = this.PlanSelectionDS.VESSEL_MF;
                    this.rgVessel.DataBind();

                }
            }


in item created
 protected void rgVessel_ItemCreated(object sender, GridItemEventArgs e)
        {
            try
            {
              

                if (!rgVessel.MasterTableView.FilterExpression.Contains("([SELECTED] = 'True' )"))
                {
                    this.rgVessel.MasterTableView.FilterExpression = "([SELECTED] = 'True' OR " + this.rgVessel.MasterTableView.FilterExpression;
                    ViewState["PlanVesselExpression"] = rgVessel.MasterTableView.FilterExpression;
                }
                else
                {
                    ViewState["PlanVesselExpression"] = rgVessel.MasterTableView.FilterExpression;
                }


but the only NAME column filteration is working correctely not working the selected column.

very urgent please help.
0
Konstantin Dikov
Telerik team
answered on 27 Jan 2014, 09:56 AM
Hello Jessy,

From the provided information It is not clear enough what your exact requirement and what you are trying to achieve.

However, if you want to set default filter on initial load, please refer to the following help article:

As a side note, please have in mind that ItemCreated will be fired for each item in the grid and you should use the PreRender event instead.

Bellow is a simple example for adding initial filter for the "SELECTED" column:
protected void rgVessel_PreRender(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        rgVessel.MasterTableView.FilterExpression = "([SELECTED] = True)";
 
        GridColumn column = rgVessel.MasterTableView.GetColumnSafe("SELECTED");
        column.CurrentFilterFunction = GridKnownFunction.EqualTo;
        column.CurrentFilterValue = "True";
        rgVessel.MasterTableView.Rebind();
    }
}

Hope that helps.


Regards,
Konstantin Dikov
Telerik
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 RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Seban
Top achievements
Rank 1
answered on 29 Jan 2014, 10:04 AM
Dear Konstantin Dikov,

Thanks for your replay.

My grid contains three columns, named as ID, NAME and SELECTED. The "SELECTED" column is template column contains one check box with Autopostback=false. And, I applied the filter to the NAME column, its a bound bound column.

When I applied the filter to NAME column, I want to show the all record based on the Name column filter and already I checked items (the SELECTED Column) in that grid.

ie., The filter condition string is : Name LIKE '%telerik%' AND SELECTED = true

please reply .
very urgent.

Thanks,
Jessy



0
Konstantin Dikov
Telerik team
answered on 03 Feb 2014, 09:56 AM
Hello Seban,

Please give a try to the approach bellow and see if the result meets your requirements:
private bool isFilterExpressionChanged = false;
 
protected void rgVessel_PreRender(object sender, EventArgs e)
{
    if (!isFilterExpressionChanged && rgVessel.MasterTableView.FilterExpression.IndexOf("Name") >= 0)
    {
        rgVessel.MasterTableView.FilterExpression += "AND ([SELECTED] = True)";
 
        GridColumn column = rgVessel.MasterTableView.GetColumnSafe("SELECTED");
        column.CurrentFilterFunction = GridKnownFunction.EqualTo;
        column.CurrentFilterValue = "True";
        rgVessel.MasterTableView.Rebind();
        isFilterExpressionChanged = true;
    }
}

Hope that helps.


Regards,
Konstantin Dikov
Telerik
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Seban
Top achievements
Rank 1
answered on 06 Feb 2014, 04:38 AM
Thank you MR.Konstantin Dikov
Tags
Grid
Asked by
Seban
Top achievements
Rank 1
Answers by
Lukas
Top achievements
Rank 1
Seban
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or