FlexGrid Sets Filter on Server side

Posted by: 048alexsandr1992 on 3 October 2017, 4:14 am EST

    • Post Options:
    • Link

    Posted 3 October 2017, 4:14 am EST

    As an experiment I want to send by ajax filterDefinition, than parse and save it in session.

    How it apply in helper ?

    
    ...
    .Filterable(f =>
                f.DefaultFilterType(FilterType.Both)
                .Id("UsersGridFilter")
                 .ColumnFilters(cfsb =>
                 {
                     cfsb.Add(cfb => cfb.Column("Id").FilterType(FilterType.None));
    
                     foreach (var item in Model.GetFilterTypes())
                     {
                         cfsb.Add(cfb => cfb.Column(item.Key).FilterType(item.Value);
                     }
                 })
                 .OnClientFilterApplied("saveFilterState")
            )
    
    

    I see in ColumnFilter method and property FilterText

    
    ValueFilter(cf=>cf.FilterText)
    
    

    Are there examples of use?

  • Posted 3 October 2017, 11:00 pm EST

    Hi,

    You cannot perform this via Razor(Html helpers). Implement this with JavaScript. http://api.jquery.com/jquery.ajax/

    
    <script>
        var cs1grid = {};
        var filterDefintionText = {};
        function saveFilterState(s, e) {
            filterDefintionText = s.filterDefinition;
            // Call ajax query here
        }
        c1.documentReady(function () {
            cs1grid = wijmo.Control.getControl("#ovFlexGrid");
        });
    </script>
    
    

    ~nilay

  • Posted 4 October 2017, 1:37 am EST

    Hi,

    You did not understand me. How save this in session I know.

    Suppose the session variable stores in string or object.

    How than its data write in Razor(Html helpers) ?

    On client side change filterDefinition is not good. When I write new value to filterDefinition, then will be called action to read Grid source data.

    So, when page reload this action will be called 2 times.

  • Posted 5 October 2017, 10:41 pm EST

    Hi,

    You can set filter definition at the server side as well which will be same as default filter type. You need to set filterDefiniton for filter as given below code:

    @(Html.C1().FlexGrid<Sale>()
        .Id("filteringGrid")
        .AutoGenerateColumns(false)
        .Bind(Model)
        .PageSize(25)
        .IsReadOnly(true)
        .Columns(columns =>
        {
            columns.Add(column => column.Binding("ID"));
            columns.Add(column => column.Binding("Start"));
            columns.Add(column => column.Binding("End").Format("t"));
            columns.Add(column => column.Binding("Country"));
            columns.Add(column => column.Binding("Product"));
            columns.Add(column => column.Binding("Color"));
            columns.Add(column => column.Binding("Amount").Format("c"));
            columns.Add(column => column.Binding("Amount2").Format("c"));
            columns.Add(column => column.Binding("Discount").Format("p0"));
            columns.Add(column => column.Binding("Active"));
        })
        .SelectionMode(SelectionMode.Row)
        .AllowSorting(true)
        .Filterable(f => {
    f.DefaultFilterType(FilterType.Both)
                .ColumnFilters(cfsb =>
                {
                    foreach (var item in filterTypes)
                    {
                        cfsb.Add(cfb => cfb.Column(item.Key).FilterType(item.Value));
                    }
                });
    	   f.filterDefinition(def);
    	}
         )
        .CssClass("grid")
    )
    

    where def will be “{“defaultFilterType”:3,“filters”:}” on page load.

    This should help!

    Thanks,

    Manish Kumar Gupta

  • Posted 6 October 2017, 12:25 am EST

    Hi, thanks, but I have error.

     
    ...
    .Filterable(f =>
            {
                f.DefaultFilterType(FilterType.Both)
                .ColumnFilters(cfsb =>
                {
                    foreach (var item in Model.GetFilterTypes())
                    {
                        cfsb.Add(cfb => cfb.Column(item.Key).FilterType(item.Value));
                    }
                });
                f.filterDefinition(Model.FilterDefinition);
            }
    
    

    “C1.Web.Mvc.Fluent.FlexGridFilterBuilder<WebSite.Security.ViewModels.UsersViewListItem>” not contain definition for “filterDefinition”.

    What assembly I must use?

  • Posted 8 October 2017, 3:31 pm EST

    Hi Alex,

    I was referring to the clientSide filter. I think I did some mistake while testing. Hence, I am sorry for that.

    Actually, FlexGridFilterBuilder is a class which converts Razor syntax to create Client side filter HTML.

    filterDefinition can not be applied on serverside. However, you can apply filterDefiniton on the client side but you need to set disableServerRead to true. This will copy complete data to client side and you can use client-side filtering, sorting and paging. In this case, you need to use BatchEdit for saving grid changes to the server.

    Thanks,

    Manish Kumar Gupta

  • Posted 8 October 2017, 3:57 pm EST

    Thanks

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels