2015-02-06 120 views
0

我有2個問題Telerik的甘特圖

  1. 動態生成的JSON對象(jsonString)爲空在kendo.data.GanttDataSource。 如何在這裏調用dataSource.read()?

var jsonObj = []; var jsonString = null; 
 
$(document).ready(function() { 
 
\t var url = test.siteUrl() + "/_vti_bin/omg/tt.svc/Read/" + _campaign.CampaignWebID + "/" + _campaign.CampaignListID + "/" + _campaign.ID + "?t=" + of360.t(); 
 
\t 
 
\t $.getJSON(url, function (data) {  
 
\t \t $.each(data, function (i) { 
 
\t \t 
 
\t \t item = {} 
 
\t \t item['ID'] = data[i].ID; 
 
\t \t item['ChannelDescription'] = data[i].ChannelDescription; 
 
\t \t item['Start'] = data[i].Start; 
 
\t \t item['End'] = data[i].End; \t 
 
\t \t item['PercentageComplete'] = data[i].BriefingState/10; 
 
\t \t item['Name'] = data[i].Name; 
 
\t \t jsonObj.push(item); 
 
\t \t }); 
 
\t \t jsonString = JSON.stringify(jsonObj); 
 
     //regex : Json remove quotes 
 
\t \t jsonString = jsonString.replace(/"(\w+)"\s*:/g, '$1:'); 
 
\t \t //alert(jsonString); 
 
\t \t 
 
\t }); 
 
}); 
 

 
var ganttModel = kendo.observable({ 
 
\t cancel: function() { 
 
\t \t this.cancelDialog(); 
 
\t }, 
 
\t isVisible: true,    
 
\t ganttDS: new kendo.data.GanttDataSource({ 
 
\t \t data: jsonString, 
 
\t \t schema: { 
 
\t \t \t model: { 
 
\t \t \t \t \t id: "id", \t \t \t 
 
\t \t \t \t fields: { 
 
\t \t \t \t \t Id: { from: "ID", type: "number" }, 
 
\t \t \t \t \t start: { from: "BriefingStart", type: "date"},         
 
\t \t \t \t \t end: { from: "BriefingEnd", type: "date" }, 
 
\t \t \t \t \t title: { from: "BriefingChannelDescription", type: "string" }, 
 
\t \t \t \t \t PercentageComplete: {from:"PercentageComplete", type: "number"} 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } \t \t 
 
\t }) 
 
});

  • 如何激活模板中的工具欄導出爲PDF?我嘗試沒有工作 數據工具欄= 「[」, 「PDF」 「]」
    數據pdfExport = 「真」
  • <script id="ganttChartTemplate" type="text/x-kendo-template"> 
     
    <div id="ganttchart"> 
     
    <div class="modal-body"> 
     
          <div class="row"> 
     
           <div class="form-group"> 
     
    \t \t \t \t \t <div data-role="gantt" 
     
    \t \t \t \t \t \t \t \t data-columns="[ \t \t \t \t 
     
    \t \t \t \t \t \t \t \t \t { field: 'title', title: 'Gattung', width: 100 }, \t \t \t \t \t \t \t \t 
     
    \t \t \t \t \t \t \t \t \t { field: 'start', title: 'Start Time', format: '{0:dd/MM/yyyy}', width: 100 }, 
     
    \t \t \t \t \t \t \t \t \t { field: 'end', title: 'End Time', format: '{0:dd/MM/yyyy}', width: 100 } \t \t \t \t \t \t \t \t \t 
     
    \t \t \t \t \t \t \t \t ]" 
     
    \t \t \t \t \t \t \t \t data-views="[ 'day', { type: 'week', selected: true }, 'month' , 'year']" 
     
    \t \t \t \t \t \t \t \t data-show-work-hours="true" 
     
    \t \t \t \t \t \t \t \t data-show-work-days="true" 
     
    \t \t \t \t \t \t \t \t data-height="300" 
     
    \t \t \t \t \t \t \t \t data-editable="false" 
     
    \t \t \t \t \t \t \t \t data-listWidth="600" 
     
    \t \t \t \t \t \t \t \t data-toolbar="[""pdf""]" \t 
     
    \t \t \t \t \t \t \t \t data-pdfExport="true" \t \t \t \t \t \t \t \t 
     
    \t \t \t \t \t \t \t \t data-bind="source: ganttDS"></div> 
     
    \t \t \t \t </div> 
     
    \t   </div> 
     
    \t \t \t <div class="k-dialog-buttons modal-footer">  
     
    
     
         <button class="k-button k-primary" data-bind="events: { click: cancel }">#= Resources.OF360.SendToBuyingDialogCancel#</button> 
     
    \t \t 
     
        </div> 
     
    \t \t </div> \t 
     
    </div> 
     
    </script>

    我在這裏感謝您的幫助。

    回答

    0
    1. 不幸的是jsonObj沒有工作,我甚至嘗試用ganttDS.read()來再次聲明它。沒有工作。 我解決了這個通過使用解析

    parse: function (response) { \t \t \t 
     
          $.each(response, function (idx, elem) {      
     
           var state = elem.BriefingState; 
     
            elem.BriefingState = state/11; 
     
          }); 
     
          return response; 
     
         } \t

    1. 數據工具欄= 「[ 'PDF']」 仍然沒有工作,我也嘗試它作爲一個花括號的字符串數組。 我解決它通過調用函數本身在我的模型

    savePdf : function(){ 
     
    \t \t var gantt = $("#gantt").data("kendoGantt"); 
     
    \t \t gantt.saveAsPDF(); 
     
    \t },