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

Kendo UI Grid

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Saranya
Top achievements
Rank 1
Saranya asked on 13 Jun 2016, 07:30 AM

Hi Team,

am using Kendo UI grid and I have a scenario where I need to set server sorting to true if I get the total number of records >= 1000, if the number of records are less than 1000 , then the server soring should set to false. I also have dynamic columns and headers.  Here is the rough code.

If I get more than "1000" records then server sorting is set to true but it triggers the read operation again continuously? Could you please help with this scenario, please let me know if am missing anything here.

this.bindWidgetData = function () {       
        $("#" + gridId+ "").empty();
        $("#" + widgetId + "").kendoGrid({
            sortable: {allowUnsort:true},
            selectable: "Single, Cell",
            resizable: true,
            pageable: false,           
            dataBound:this.dataBound,
            change: function (e) {
                var i = 10;
            }
            //dataBinding: this.dataBinding,
        })
 setGridData();
}
  
this.setGridData = function () {
        var gridData = $("#" + this.gridid).data("kendoGrid");     
        _widgetCallParams = this.getCallParameters();
        this.UpdateSortInfo(sort);
        var dataSource = new kendo.data.DataSource({
            transport: {
                read: function (options) {                   
                    $.ajax({
                        url: getBaseURL() + "WSIHome/GetCustomListData",
                        dataType: "json", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests                       
                        data: _widgetCallParams,
                        type: "POST",
                        success: function (result) {                          
                            var columns = _this.getGridColumnsHeadersandFormat(result.data);
                            gridData.setOptions({
                                columns: columns
                            });
                            gridData.dataSource.options.serverSorting = (result.rowtotal) >= _widgetCallParams.TopX ? true : false;                          
                            options.success(result);
                        },
              
            schema: {
            data: "data",
            total: "rowtotal"// twitter's response is { "results": [ /* results */ ] }
            },
           
        });
      
        gridData.setDataSource(dataSource);
    };

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 15 Jun 2016, 07:49 AM
Hi,

The setOptions method recreates the grid with the new options and the grid automatically reads the dataSource on initialization unless the autoBind option is set to false. You can avoid the loop by setting the autoBind option to false and manually calling fetch on the dataSource:
$("#" + widgetId + "").kendoGrid({
    autoBind: false,
    ...
gridData.setDataSource(dataSource);
dataSource.fetch();


Regards,
Daniel
Telerik
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Grid
Asked by
Saranya
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or