Problems with default Operator on Filter

4 posts, 0 answers
  1. OfficialCommunity
    OfficialCommunity avatar
    10 posts
    Member since:
    May 2006

    Posted 19 Feb 2015 Link to this post

    Currently using version 2014.3.1411.

    I am trying to always filter on the "contains" operator for string columns in my grid.

    The problem is that when I start typing in any of the the filters, a request is sent to the 
    DataSource Read with the following data:

    sort:page:1group:filter:Name~startswith~'t'

    Then after a delay a second call is sent:

    sort:page:1pageSize:5group:filter:Name~contains~'t'

    The second call is correct. It has the correct pageSize and filter.

    In the grid I have removed all filters except Contains and assigned an Operator("contains") to each filtered cell.

    If I inspect the Filter i see this:

    <input data-bind="value: value" data-role="autocomplete" data-text-field="Name" data-filter="startswith" data-delay="100" data-min-length="1" data-value-primitive="true" type="text" class="k-input" autocomplete="off" role="textbox" aria-haspopup="true" aria-disabled="false" aria-readonly="false" aria-autocomplete="list" aria-owns="" style="width: 100%;" aria-busy="false"><br>

    This is the grid:

    @helper RenderProductsSearch()
    {
        @(Html.Kendo().Grid<ViewableSelectableProduct>()
                  .Name("grid-products-search-#=ID#")
                  .AutoBind(true)
                  .Pageable(pager => pager
                        .Input(true)
                        .Numeric(true)
                        .Info(true)
                        .PreviousNext(true)
                        .Refresh(true)
                        .PageSizes(true)
                  )
                  .Scrollable()
                  .Sortable()
                  .Navigatable()
                  .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
                  .HtmlAttributes(new { style = "height: 100%; border: 0;" })
                  .Columns(columns =>
                  {
                      columns.Bound(e => e.Name).Width(300).Title("name").Filterable(f => f.Cell(cell => cell.Operator("contains").ShowOperators(false).Delay(100)));
                      columns.Bound(e => e.Sku).Width(200).Title("sku").Filterable(f => f.Cell(cell => cell.Operator("contains").ShowOperators(false).Delay(100)));
                      columns.Bound(e => e.ShortDescription).Title("description").Filterable(f => f.Cell(cell => cell.Operator("contains").ShowOperators(false).Delay(100)));
                      columns.Command(command => command.Custom("Select").Click("selectProduct"))
                                .Title("commands")
                                .Width(Constants.Columns.Default.Widths.ColumnCommands);
                  })
                   .Filterable(filterable => filterable
                        .Extra(false)
                        .Operators(ops => ops
                            .ForString(str => str.Clear()
                                .Contains("Contains")
                                )))
                  .DataSource(dataSource => dataSource
                      .Ajax()
                      .Model(model =>
                      {
                          model.Id(p => p.Id);
                          model.Field(x => x.Id).Editable(false);
                          model.Field(x => x.Name).Editable(false);
                          model.Field(x => x.Sku).Editable(false);
                          model.Field(x => x.ShortDescription).Editable(false);
                      })
                      .PageSize(5)
                      .Events(events =>
                      {
                          events.Error("standard_grid_error_handler");
                      })
                      //.Batch(true)
                      .ServerOperation(true)
                      .Read(read => read.Action("ReadSelectable", "Product", new { blockId = "#=ID#" }))
                  )
                  .ToClientTemplate()
        )
    }


    Why is the first call happening and why does the input data-filter contain the wrong operator?

    thanks








  2. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 23 Feb 2015 Link to this post

    Hi,

    In order to set the autocomplete operator you should use the SuggestionOperator option:

    .Filterable(f => f.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)
         .ShowOperators(false).Delay(100)))


    Regards,
    Rosen
    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.

     
  3. Kyle Smith
    Kyle Smith avatar
    44 posts
    Member since:
    Feb 2012

    Posted 17 Mar 2015 in reply to Rosen Link to this post

    I have the following column definition:

    columns.Bound(x => x.Name).Width(140).Filterable(f => f.Cell(c => c.Operator("eq").SuggestionOperator(FilterType.Contains).ShowOperators(false).InputWidth(120)));

    However, the "Contains" for the suggestion is not honored:
    sort=&page=1&group=&filter=Name~startswith~'f'

    Generated javascript for the column:
    {"title":"Name","width":"140px","field":"Name","filterable":{"cell":{"showOperators":false,"inputWidth":120}},"encoded":true,"editor":null}
  4. Kyle Smith
    Kyle Smith avatar
    44 posts
    Member since:
    Feb 2012

    Posted 17 Mar 2015 in reply to Kyle Smith Link to this post

    Nevermind! I updated to the latest and it is working now.
Back to Top