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

FilterType CheckList not working

3 Answers 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Guilhem
Top achievements
Rank 1
Guilhem asked on 10 May 2017, 01:11 AM

Hello,

I saw many posts with issues on filters, but none of them looks similar to my issue.
The classic filter works perfectly but the Checklist filter doesn't. If I try Combined, the classic functionnality works and the checklist doesn't.
Please note that I tried to change the binding way for my grid (using the NeedDataSource event), but it doesn't change anything. The classic filter is still working while the checklist filter still doesn't.

Here is some part (that I think pertinent) of my code. I generate everything from code behind in the Page_Load method:

var grid = new RadGrid();
grid.DataSourceID = myDataSource;
grid.AllowPaging = false;
grid.ColumnCreated += Grid_ColumnCreated;
grid.AutoGenerateColumns = true;
grid.AllowFilteringByColumn = true;
grid.FilterType = GridFilterType.Combined;
grid.FilterCheckListItemsRequested += Grid_FilterCheckListItemsRequested;
grid.ClientSettings.Scrolling.AllowScroll = true;
grid.ClientSettings.Scrolling.UseStaticHeaders = true;
grid.MasterTableView.TableLayout = GridTableLayout.Auto;

grid.ItemCommand += Grid_ItemCommand;

protected void Grid_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
{
    RadGrid grid = sender as RadGrid;
    if (e.Column is GridBoundColumn)
    {
        GridBoundColumn column = (GridBoundColumn) e.Column;
        column.AutoPostBackOnFilter = true;
        column.FilterCheckListEnableLoadOnDemand = true;
        column.CurrentFilterFunction = GridKnownFunction.Contains;
    }
}
private void Grid_FilterCheckListItemsRequested(object sender, GridFilterCheckListItemsRequestedEventArgs e)
        {
            string dataField = (e.Column as IGridDataColumn).GetActiveDataField();
 
            var grid = sender as RadGrid;
            var ds = grid.DataSourceObject as SqlDataSource;
            Regex reg = new Regex("FROM(.+)ORDER");
            string request = "SELECT DISTINCT t." + dataField + " " + reg.Match(ds.SelectCommand).Value + " BY t." + dataField + " ASC";
 
            e.ListBox.DataSource = GetFilterTable(request);
            e.ListBox.DataKeyField = dataField;
            e.ListBox.DataTextField = dataField;
            e.ListBox.DataValueField = dataField;
            e.ListBox.DataBind();
        }

 

The FilterCheckListItemsRequested is working and I have, for each columns, 1 checkbox for each different values inside. Notice however how I had to make a Regex on the SelectCommand as I don't know which grid I'm in inside this event. (If someone has a better way ?).

Anyway, regarding the checklist filter, when I check a checkbox and click on "Apply", a postback is done and the Grid_ItemCommand event is raised. However it looks like the "filter value" is empty.

private void Grid_ItemCommand(object sender, GridCommandEventArgs e)
{
    if(e.CommandName == RadGrid.FilterCommandName)
    {
        GridFilteringItem filter = (GridFilteringItem) e.Item;
        string value = ((filter[currentCol].Controls[0]) as TextBox).Text;
         
        Pair command = (Pair) e.CommandArgument;
 
        /* IF CLASSIC FUNCTIONNALITY IS USED
        *   command.First = "Contains"
        *   command.Second = myColumnName
        *   value = theFilterStringIInputed
        */
         
        /* IF CHECKLIST FUNCTIONNALITY IS USED
        *   command.First = "5"
        *   command.Second = myColumnName
        *   value = Empty
        */
    }
}

 

Does someone know how to get the values of the selected checkbox ?

Or what did I do wrong here ?

Thank you.
Regards,
Guilhem

 

 

3 Answers, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 15 May 2017, 07:28 AM
Hi Guilhem,

Can you try moving the Grid-creation logic to the Page_Init handler and see whether the problem persists? Another thing I will advice that you do (as there are some missing functions in the provided snippets) is to compare the logic in your project with the caonfiguration given in the following help article and see whether there is any difference between them:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/filtering/checklist-filtering

If none of the above helps in resolving the case, please, prepare a runnable version of your project including all used functions and a dummy data we can test with, so we can examine it further at our end.

Regards,
Vessy
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Guilhem
Top achievements
Rank 1
answered on 16 May 2017, 01:37 AM

Hello Vessy,

Thank you for your answer.

I moved the function to the Page_Init handler but the issue persists.
When I do, I also got an additional error message regarding the filter command "5" not being recognized. Easily fixed by canceling the current filter command and firing a "contains" filter command instead. But as there are no value in the filter, the behavior is the same.
Regarding your link, that's the one I used to create my code (maybe I missed something but I checked a few times).

I created a ticket (#1109156). Please feel free to look into it.

Thank you

0
Vessy
Telerik team
answered on 16 May 2017, 01:55 PM
Hi,

Thank you for the cooperation, Guilhem - I will follow up in the created ticket shortly.

Regards,
Vessy
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Guilhem
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Guilhem
Top achievements
Rank 1
Share this question
or