LP13
LP13

Reputation: 34109

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());
}

Upvotes: 5

Views: 7323

Answers (2)

Rahul Gupta
Rahul Gupta

Reputation: 10141

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
}

Upvotes: 4

Cara
Cara

Reputation: 644

Try using

$("#mygrid").data('kendoGrid')

It returns undefined if it's not an instance of kendo grid

Upvotes: 3

Related Questions