Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI - How to check if instance is kendoGrid instance or check if grid is initialized on the given DOM element

I have a common method which does some operations on kendo grid instance. The caller can pass jQuery instance or actual kendo grid instance to this common method

function commomMethod(grid)
{
    //?? How do i check if `grid` instance is not KendoGrid instance
    if(grid is not kendoGrid)
    {
       grid = grid.getKendoGrid();
    }
    //do something
}


function caller1()
{
   commomMethod($("#mygrid"));
}

function caller2()
{
   commomMethod($("#mygrid").getKendoGrid());
}
like image 471
LP13 Avatar asked Sep 26 '17 19:09

LP13


1 Answers

Here is the working DEMO

Below is the code snippet from the demo:

function commomMethod(grid)
{
    var kendoGrid = $(grid).data("kendoGrid");

    //Check if the element is already initialized with the Kendo Grid widget
    if (kendoGrid)//Grid is initialized
    {
       alert("Yess, Kendo grid is initialized");
    }
    else
    {
        //grid is not initialized
        alert("Nopeee, Kendo grid not is initialized");

        //To verify, you change the id here  to  $("#mygrid1").kendoGrid({
    }
    //do something
}
like image 176
Rahul Gupta Avatar answered Sep 17 '22 16:09

Rahul Gupta