Telerik Gantt图表

时间:2015-02-06 12:00:47

标签: javascript jquery kendo-ui kendo-dataviz

我有2个问题

  1. 动态生成的JSON对象(jsonString)在kendo.data.GanttDataSource中为空。 我如何在这里调用dataSource.read()?
  2. 
    
    var jsonObj = []; var jsonString = null;
    $(document).ready(function () {
    	var url = test.siteUrl() + "/_vti_bin/omg/tt.svc/Read/" + _campaign.CampaignWebID + "/" + _campaign.CampaignListID + "/" + _campaign.ID + "?t=" + of360.t();
    	
    	$.getJSON(url, function (data) {    
    		$.each(data, function (i) {
    		
    		item = {}
    		item['ID'] = data[i].ID;
    		item['ChannelDescription'] = data[i].ChannelDescription;
    		item['Start'] = data[i].Start;
    		item['End'] = data[i].End;	
    		item['PercentageComplete'] = data[i].BriefingState/10;
    		item['Name'] = data[i].Name;
    		jsonObj.push(item);
    		});
    		jsonString = JSON.stringify(jsonObj);
            //regex : Json remove quotes
    		jsonString = jsonString.replace(/"(\w+)"\s*:/g, '$1:');
    		//alert(jsonString);
    		
    	});
    });
    
    var ganttModel = kendo.observable({  
    	cancel: function () {
    		this.cancelDialog();
    	}, 
    	isVisible: true,               
    	ganttDS: new kendo.data.GanttDataSource({
    		data: jsonString,
    		schema: {
    			model: {   
    					id: "id",			
    				fields: {
    					Id: { from: "ID", type: "number" },
    					start: { from: "BriefingStart", type: "date"},                                
    					end: { from: "BriefingEnd", type: "date" },
    					title: { from: "BriefingChannelDescription", type: "string" }, 
    					PercentageComplete: {from:"PercentageComplete", type: "number"}
    				}
    			}
    		}		
    	})
    });
    
    
    

    1. 如何在模板中激活工具栏导出为PDF?我的尝试没有用 数据栏=" ["" PDF""]"
                                      数据pdfExport ="真"
    2. 
      
      <script id="ganttChartTemplate" type="text/x-kendo-template">
      <div id="ganttchart"> 
      <div class="modal-body">
                  <div class="row">
                      <div class="form-group">
      					<div data-role="gantt"
      								data-columns="[				
      									 { field: 'title', title: 'Gattung', width: 100 },								
      									 { field: 'start', title: 'Start Time', format: '{0:dd/MM/yyyy}', width: 100 },
      									 { field: 'end', title: 'End Time', format: '{0:dd/MM/yyyy}', width: 100 }									 
      								 ]"
      								data-views="[ 'day', { type: 'week', selected: true }, 'month' , 'year']"
      								data-show-work-hours="true"
      								data-show-work-days="true"
      								data-height="300"
      								data-editable="false"
      								data-listWidth="600"
      								data-toolbar="[""pdf""]"	
      								data-pdfExport="true"								
      								data-bind="source: ganttDS"></div>
      				</div>
      	        </div>
      			<div class="k-dialog-buttons modal-footer">      
      
              <button class="k-button k-primary" data-bind="events: { click: cancel }">#= Resources.OF360.SendToBuyingDialogCancel#</button>
      		
          </div>
      		</div>	
      </div>
      </script>
      &#13;
      &#13;
      &#13;

      感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

  1. 不幸的是jsonObj没有用,我甚至尝试用ganttDS.read()再次断言它。没有用。 我通过使用解析
  2. 解决了这个问题

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

    1. data-toolbar =“['pdf']”仍然无效,我也尝试将其作为带花括号的字符串数组。 我通过在我的模型中调用函数本身来解决它
    2. savePdf : function(){
      		var gantt = $("#gantt").data("kendoGantt");
      		gantt.saveAsPDF();
      	},