Sorting and Filtering Not working in Kendo Grid

10 posts, 0 answers
  1. Amanda.Hicks@navcanada.ca
    Amanda.Hicks@navcanada.ca avatar
    1 posts
    Member since:
    Sep 2012

    Posted 04 Feb 2014 Link to this post

    I am just starting to use the Telerik kendo grid so not sure if I left something out

    We have an MVC project and are using razr views.  I have a Kendo grid displaying the results of a dynamic SQL query which doesn't allow for sorting or filtering.   Are these attributes inherent in the grid or am I missing something?

    My grid:

    @(Html.Kendo().Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
    foreach (System.Data.DataColumn column in Model.Columns)
    {
      columns.Bound(column.ColumnName).Groupable(true).Sortable(true).Filterable(true);
    }
    })
    .Sortable(sortable => sortable.AllowUnsort(false))
    .Scrollable()
    .Filterable()
    .Groupable()
    .DataSource(dataSource => dataSource
    .Ajax()
    .Model(model =>
    {
    foreach (System.Data.DataColumn column in Model.Columns)
    {
    if (column.ColumnName.Contains("-"))
    {
    column.ColumnName = column.ColumnName.Replace("-", "");
    }
    model.Field( column.ColumnName , column.DataType);
    }
    })
    .Read(read => read.Action("ReadData", "Grid"))
    )
    )

    My data source:

    public ActionResult ReadData([DataSourceRequest] DataSourceRequest request, int id)
    {
    DataTable queryResults = QueryResults(id);
    return Json(queryResults.ToDataSourceResult(request), "text/html", System.Text.Encoding.Unicode, JsonRequestBehavior.AllowGet);
    }

    private DataTable QueryResults(int id)

    {

    String queryString = (from a in _qryList where a.Id == id select a.Sql).First() ;
    var dataTable = new DataTable();
    try
    {
    var dataAdapter = new SqlDataAdapter(queryString, connection);
    dataAdapter.Fill(dataTable);
    }
    catch (SqlException e)
    {
    ViewBag.TextareaHTML = "Your SQL Query is invalid.\r"+e.Message;
    }
    return dataTable;

    }

    Thanks
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 05 Feb 2014 Link to this post

    Hello Amanda,

    Basically after the Read controller is reached the data gets stored in the Grid's DataSource, which supports client-side operations like sorting and filtering (see serverOperation option).

    Regards,
    Alexander Popov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Paolo
    Paolo avatar
    26 posts
    Member since:
    Nov 2015

    Posted 12 Nov 2015 Link to this post

    In Kendo UI for PHP I have the same problem on a grid.

    Filtering and sorting display an empty grid.

    The mysql query log shows sorting is missing the order by field:

    1096 Query SELECT a.idPDV, a.codiceSAP, a.ragioneSociale, a.indirizzo, a.CAP, a.comune, a.telefono FROM anagraficapdv a ORDER BY  LIMIT 0,10

    and the filter query log shows that the where clause is empty in the count query:

    1100 Query  SELECT COUNT(*) FROM anagraficapdv a  WHERE ()

    I have the same code working on other grids and I use this method fr the grid options:

    $grid
            ->addColumn($idpdvCol)
            ->addColumn($category)
            ->addColumn($supplier)
            ->dataSource($dataSource)
            ->pageable(true)
            ->editable("popup")
            ->selectable('row single')
            ->change("onChange")
            ->dataBound('onDataBound')
            ->dataBinding('onDataBinding')
            ->sortable(true)
            ->resizable(true)
            ->reorderable(true)
            ->filterable(true);

    Any suggestions?
  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 16 Nov 2015 Link to this post

    Hi Paolo,

    I am afraid that the provided information does is not sufficient to determine what causes the issue. Would you please share the DataSource configuration as well as the server-side PHP code responsible for handling the read requests? 

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. Mark
    Mark avatar
    4 posts
    Member since:
    Oct 2015

    Posted 07 Jan in reply to Alexander Popov Link to this post

    this is no help

    using the grid builder fluent syntax, with either a strongly typed model or not, the filter does not work at all.

    the read method gets pounded every time the filter on the column is accessed on the page, but there are no messages in the command for the filter, and the client side code is either missing or broken.

    since there is no documentation on any theory of operations, and the examples all look like what I have,  I don't see the value of a telerik solution.

  7. Mark
    Mark avatar
    4 posts
    Member since:
    Oct 2015

    Posted 07 Jan Link to this post

    for the mvc extensions, in the datasource, there is support for .ServerOperation(<true | false>)

    for client operation - false, for server operation - true

    the grid will post the sort,filter,page,pagesize,aggregate,... in the forms string of the http request so that you can handle that in your data rendering.

    nothing works if .ServerOperation(true) and you don't handle it on the server side.  The trick is to find the grid state for the current options.  AFAIK, there is nothing on the telerik website doco for this.

  8. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 11 Jan Link to this post

    Hello Mark,

    I am not sure I understand you very well. Basically, if the ServerOperation option is set to false, then the Read should be performed once. All following operations such as paging, filtering and etc should be performed on the client side without any further requests to the server. Setting the ServerOperation to true will send the DataSourceRequest arguments to the server, where they should be handled by the ToDataSourceRequest method, as explained in the Grid Ajax binding article. 

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  9. Mark
    Mark avatar
    4 posts
    Member since:
    Oct 2015

    Posted 11 Jan in reply to Alexander Popov Link to this post

    sorry, the referenced example has a lot of noise about creating a sample project.  somewhere in there, the reference to the helper markup shows the .ServerOperation() option on the helper, but does not explain how the sort and filter conditions are sent to the server callback.  The answer is in the httprequest form variables sort and filter.  not in the datasourcerequest object as I would expect.

    As noted above, the .ServerOperation() should always be stated so that you don't see random behaviors such as I have noticed during debugging (the grid seems to pick client or server on it's own, or based on some prior context)

  10. Mark
    Mark avatar
    4 posts
    Member since:
    Oct 2015

    Posted 11 Jan in reply to Alexander Popov Link to this post

    I *thought* I posted that response to myself on this forum, but I guess I just answered the question when I closed the support ticket.  The question was 'where or how are the sort and filter conditions passed back to the server when using server side sorting and filtering"  the answer is in the httprequest form variables
  11. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 12 Jan Link to this post

    Hi Mark,

    Parameters are sent through the form data and parsed on the server by the DataSourceResult ModelBinder. For further information, please check the following:

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready