2017-09-26 3 views
0

J'ai une méthode commune qui effectue certaines opérations sur l'instance kendo grid. L'appelant peut passer par exemple jQuery ou une instance réelle de la grille de kendo à cette méthode communeKendo UI - Comment vérifier si instance est une instance de kendoGrid ou vérifier si la grille est initialisée sur l'élément DOM donné

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

Répondre

0

Essayez d'utiliser

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

Il retourne undefined si ce n'est pas une instance de grille kendo

0

Voici le travail DEMO

est Ci-dessous l'extrait de code de la démo:

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 
} 
+0

Avez-vous déjà essayé ma solution? Faites-moi savoir si vous avez des problèmes ou si vous pouvez accepter et voter ma réponse :) –