How can I know whether kendo grid rendering finished or not?

1 Answer 5468 Views
Grid
hustcer
Top achievements
Rank 1
hustcer asked on 06 May 2014, 10:28 AM
How can I know whether kendo grid rendering finished or not?
I want to do something after the grid was rendered, but there isn't a 'rendered' event, Any suggestions?

BTW:
If I init a kendoGrid with the following data source:
$("#grid").kendoGrid({<br>  dataSource: [<br>    { name: "Jane Doe", age: 20 },<br>    { name: "John Doe", age: 30 }<br>  ]<br>});


How can I show commandA when age<25, and commandB when age>25?
Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 06 May 2014, 12:30 PM
Hello Justin,

If you would like to access the Grid rows, you should bind to the dataBound event, which is fired when the data is ready. For most of the other tasks you could use document.ready.

As for the second question, you could achieve this in the dataBound event handler i.e. access the Grid rows, retrieve the associated models, check the age value and hide/remove the unneeded command buttons. Here is an example, which demonstrates the approach in action.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
hustcer
Top achievements
Rank 1
commented on 06 May 2014, 01:25 PM

Thank you very much, I got it!
hustcer
Top achievements
Rank 1
commented on 06 May 2014, 02:16 PM

It works, but render the buttons and then remove it, It's not that natural. There is a bad smell, IMO.
Dimiter Madjarov
Telerik team
commented on 06 May 2014, 02:41 PM

Hi Justin,


I am not sure what is the scenario and the exact Grid configuration on your side. Please share some additional details and if possible a runnable example (you could update mine too), so I could assist you further.

I am looking forward to hearing from you.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
hustcer
Top achievements
Rank 1
commented on 06 May 2014, 02:48 PM

I mean the first problem was resolved. but the second one:
My situation is quite similar to this one:
http://jsbin.com/notukesu/2/edit
It works but:
dataBound: function(){
    var grid = this;
    grid.tbody.find("tr").each(function(e){
      var model = grid.dataItem(this);
       
      if(model.age < 25) {
        $(this).find(".k-grid-edit").remove();
      }
    });
  }

the buttons was rendered and then removed, I think render them conditionally is better.

Dimiter Madjarov
Telerik team
commented on 06 May 2014, 03:16 PM

Hello Justin,


Conditional rendering of the Grid commands is not supported. Nevertheless you could achieve this with a template column. The downside of this approach is that you should manually add the command markup to the cell. The Grid will then automatically attach the appropriate handlers through jQuery delegates. Here is the updated example.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
hustcer
Top achievements
Rank 1
commented on 06 May 2014, 03:21 PM

Thanks very much
Harlan
Top achievements
Rank 1
commented on 01 Apr 2016, 04:06 PM

The dataBound and document ready events did not work for what we needed. Instead we opted to use the kendoWidgetCreated event and check to see that all the controls that we cared about had been created, like this (we're using AngularJS):

 

$scope.$on("kendoWidgetCreated", function (e) {
    if ($scope.grid && $scope.makeFilter && $scope.modelFilter) {
        $scope.grid.resizeGrid();
    }
})

Tags
Grid
Asked by
hustcer
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or