2013-04-15 16 views
9

Qualcuno è stato in grado di utilizzare il metodo setdatasource della griglia dell'interfaccia utente di Kendo? Credo che questo sia usato per assegnare l'origine dati che può essere assegnata alla griglia in una fase successiva e anche per scopi di aggiornamento della griglia. Tuttavia non sono riuscito a trovare alcuna documentazione adeguata che spieghi come utilizzare questo metodo e creare una griglia aggiornabile.Come utilizzare il metodo SetDataSource della griglia dell'interfaccia utente Kendo

Sto tentando di aggiornare la mia origine dati tramite chiamata ajax remota. Ho anche presupposto che dovrebbe eseguire l'authorfresh quando la sorgente viene aggiornata impostando la proprietà autosync su true. Ogni volta che faccio clic sul controllo del calendario, trasferisco un valore di data alla funzione GetRemoteData in modo che i dati vengano aggiornati tramite la richiesta Ajax.

Questo non funziona al momento. Qualche indizio su quale sia la soluzione per questo?

My View

$('#calendarContainer').kendoCalendar({ 
     format: "dd/MM/yyyy", 
     culture: "en-GB", 
     change: onDateChange 
    }); 


function onDateChange() { 
     var selectedDate = kendo.toString(this.value(), 'dd/MM/yyyy'); 

     GetRemoteData(selectedDate); 
     /* 
     $("#grid").data("kendoGrid").dataSource.data(bob); 
     $("#grid").data("kendoGrid").dataSource.read(); 
     */ 
    } 



    $('#grid').kendoGrid({ 

      dataSource:GetRemoteData(date), 

      scrollable: { 
       virtual: true 
      }, 
      navigatable: true, 
      groupable: true, 
      sortable: true, 
      selectable: "row", 
      pageable: true, 

      pageable: { 
       input: true, 
       numeric: false 
      }, 

      resizable: true, 
      reorderable: true, 
      filterable: { 
       extra: false 
      }, 
      columns: [ 
       { 
        field: "DealNumber", 
        width: 150, 
        title: "DealNumber", 
        filterable: { 
         operators: { 
          string: { 
           startswith: "Starts With", 
           contains: "Contains" 
          } 
         } 

        }, 

       }, 
       { 
        field: "DealIssuer", 
        width: 150, 
        title: "Issuer", 
        filterable: { 
         operators: { 
          string: { 
           startswith: "Starts With", 
           contains: "Contains" 
          } 
         } 
        } 

       }, 
        { 
         field: "Ticker", 
         width: 150, 
         title: "Ticker", 
         filterable: { 
          operators: { 
           string: { 
            startswith: "Starts With", 
            contains: "Contains" 
           } 
          } 
         } 

        }, 
        { 
         field: "DealType", 
         width: 150, 
         title: "Type", 
         filterable: { 
          operators: { 
           string: { 
            startswith: "Starts With", 
            contains: "Contains" 
           } 
          } 
         } 

        }, 
         { 
          field: "DealValue", 
          width: 150, 
          title: "Value", 
          filterable: { 
           operators: { 
            string: { 
             startswith: "Starts With", 
             contains: "Contains" 
            } 
           } 
          } 

         }, 
          { 
           field: "DealStatus", 
           width: 150, 
           title: "Status", 
           filterable: { 
            operators: { 
             string: { 
              startswith: "Starts With", 
              contains: "Contains" 
             } 
            } 
           } 

          }, 
       { 
        field: "DealPricingCompletionDate", 
        width: 230, 
        title: "DealPricingCompletionDate", 
        format: "{0:dd/MM/yyyy}", 
        // template: '#= kendo.toString(StartDate, "dd/MM/yyyy") #', 
        filterable: { 
         ui: "datetimepicker", 
         operators: { 
          date: { 
           gt: "After", 
           lt: "Before", 
           eq: "Equals" 
          }, 
          messages: { 
           filter: "Apply", 
           clear: "Clear" 
          } 
         } 

        } 
       }, 

       { 
        command: { text: "View Details", click: showDetails }, title: " ", width: "140px" 
       }, 

      ], 
      editable: "popup", 
      height: 600 
     }).data("kendoGrid"); 






function GetRemoteData(date) { 

     var chosenDate; 


     if (typeof date == "undefined") { 
      chosenDate = "12-12-2013"; 
     } 
     else { 
      chosenDate = date; 
     } 

     var source = new kendo.data.DataSource({ 
      autoSync: true, 
      transport: { 
       read: { 
        type: "GET", 
        url: "http://localhost:35798/RestServiceImpl.svc/GetDealData", 
        dataType: "jsonp", 
        contentType: "application/json; charset=utf-8", 
        cache: false, 
       }, 

       parameterMap: function (data, type) { 

        var data = { 
         startDate: chosenDate 
        } 
        return data; 
       } 
      }, 
      schema: { 
       model: { 
        fields: { 
         DealNumber: { type: "string" }, 
         DealIssuer: { type: "string" }, 
         Ticker: { type: "string" }, 
         DealType: { type: "string" }, 
         DealValue: { type: "number" }, 
         DealStatus: { type: "string" }, 
         DealPricingCompletionDate: { type: "date" } 

        } 
       } 
      }, 
      pageSize: 16 
     }); 

     source.fetch(function() { 
      var data = this.data(); 
     }); 
     return source; 
    } 

risposta

15

Cosa hai provato finora? Questo è piuttosto semplice.

Esempio:

var ddl = $('#testDropDown').data("kendoDropDownList"); 
var otherDropDownList= $('#otherDropDown').data("kendoDropDownList"); 

var ds = new kendo.data.DataSource(); 
ds.data(otherDropDownList.dataSource.data()); // set new DataSource to otherDropDown's data source then filter it 
ds.filter(
    { 
     field: "Id", 
     operator: "eq", 
     value: parseInt(id) 
    } 
) 

ddl.setDataSource(ds); 

Ovviamente questo è tutto sta per essere diverso per qualsiasi scenario di cui si dispone.

Aggiornamento per Griglia

var ds = new kendo.data.DataSource(); 
var grid = $('#grid').data("kendoGrid"); 

grid.setDataSource(ds); // sets to a blank dataSource 

Oppure, utilizzare questo dataSource con un'altra griglia?

var gridDataSource = $('#grid').data("kendoGrid").dataSource; 
var secondGrid = $('#secondGrid').data("kendoGrid"); 

secondGrid.setDataSource(gridDataSource); 
+0

HI thedixon. Grazie per il codice, ma sto cercando di fare lo stesso con la griglia. Ho provato tutti i tipi di opzione, ma nessuno ha funzionato fino a quando non ho trovato questo metodo chiamato setDataSource. Sareste in grado di mostrare l'esempio in questo modo per Grid. Posso pubblicare il mio codice se vuoi vedere dove può essere adattato. – Sike12

+0

Sì, se potessi pubblicare il tuo codice corrente e quello che stai cercando di fare, sarebbe fantastico. –

+0

Il codice è stato incluso ora – Sike12

5

Se si desidera impostare l'setDataSource altro modo è la creazione di un DataSource dalla oggetto restituito dalla vostra richiesta Ajax come spiegare nel seguente LINK da Brett

var dataSource = new kendo.data.DataSource({ 
    data: "your object returned by ajax" 
}); 

$('#GridKatildigiKurslar').data('kendoGrid').setDataSource(dataSource); 

fuori rotta la griglia dovrebbe essere configurato per mostrare l'oggetto restituito.

+0

Grazie @freedeveloper – Sike12

Problemi correlati