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

Grid with Filter Row using ajax call action two times

3 Answers 33 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Oscar Agusti
Top achievements
Rank 1
Oscar Agusti asked on 08 Oct 2015, 10:56 AM

Hi,

I created a Grid with Filter Row and using ajax:

@(Html.Kendo().Grid<Products>()
    .Name("grid")
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(10)
        .ServerOperation(true)
        .Model(model => model.Id(p => p.Id))
                  .Read(read => read.Action("GetList", "CurrentController").Data("HandleFilters")).PageSize(10)
    )
    .Columns(columns =>
    {
        columns.Bound(model => model.Name).
            Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")).
                Operators(m => KendoUICustomLocalization.GridFilterLocalization(m)));
        columns.Bound(model => model.LastName).
            Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")).
                Operators(m => KendoUICustomLocalization.GridFilterLocalization(m)));
         
         
    })
    .Pageable(p => p.Messages(m => KendoUICustomLocalization.GridPageLocalization(m))
    .PageSizes(10))
    .Sortable() // Enable sorting
    .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
    .Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
    .Excel(excel => excel
        .FileName("Excel.xlsx")
        .Filterable(true)
        .AllPages(true)
        .ProxyURL(Url.Action("Excel_Export_Save", "CurrentController"))
    )
    .Events(events => events.Change("onGridChange"))
    )

 

 and the GetList action:

public ActionResult GetList([DataSourceRequest]DataSourceRequest request, string filtro_texto)
        {
            IQueryable<Products> products = _uow.GetProducts();
 
            .............
 
            DataSourceResult result = products_model.ToDataSourceResult(request);
            return Json(result, JsonRequestBehavior.AllowGet);          
        }

I see that the GetList action is called two times, one with the request pageSize = 0, and other with the request pageSize = 10

Is there any problem in my code? Is it a nomal behaviour?

 

Best regards

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 12 Oct 2015, 06:50 AM

Hello Oscar,

Indeed, this is the designed behavior. The controller action is called multiple times as the grid's DataSource is cloned and assign as DataSource for the AutoComplete widget inside the filter row. This is due to the fact that no specific DataSource is set via the Column filterable settings. You can assign a separate DataSource for the filter row cell similar to the following:

.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").DataSource(dataSource => dataSource.Read("MyAction", "Controller"))))

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jeffrey
Top achievements
Rank 1
Veteran
answered on 19 Feb 2018, 04:18 PM

Ok.  I now understand why I get two read requests with one of page size 0.  I also see that i can put a separate Action on this request so it goes to a different method.  My question is what am i suppose to return?  What is the point of it?  What is it used for?

 

Thank you,

Jeff

0
Stefan
Telerik team
answered on 21 Feb 2018, 08:32 AM
Hello, Jeffrey,

Regarding the questions:

1) The data which should be shown in the AutoComplete filter has to be returned.

2) The point and the use of it are that the developer may need to return a different set of data for the AutoComplete.  For example is the scenario, where the user may be allowed to filter only on some of the value not all of them.

Let me know if you need additional information on this matter.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 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
Oscar Agusti
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Jeffrey
Top achievements
Rank 1
Veteran
Stefan
Telerik team
Share this question
or