自定义render并使用

来自ling
跳转至: 导航搜索
var ProgressCellRenderer = $extend(dorado.widget.grid.SubControlCellRenderer, {
    createSubControl: function(arg) {
        return new dorado.widget.ProgressBar({
            value:arg.data.get("percent")
        });
    },

    refreshSubControl: function(progressBar, arg) {
		progressBar.set("value", arg.data.get("percent"));
    }
});


/** @Bind #gridFiles1.onCreate */
/** @Bind #gridFiles2.onCreate */
!function(self){
	self.set("&percent.renderer", new ProgressCellRenderer());
};
var UploadCellRenderer = $extend(dorado.widget.grid.SubControlCellRenderer, {
    createSubControl: function(arg) {
    	var data = arg.data;
    	var actionId = dorado.Core.newId();
    	var buttonId = dorado.Core.newId();
    	var uploadAction = new dorado.widget.UploadAction({
    		id : actionId,
    		maxFileSize: "1MB",
    		autoUpload: true,
    		iconClass: "fa fa-upload",
    		fileResolver: "myUploadProcessor#process1",
    		onFilesAdded: function(arg){
    			var file = arg.files[0];
    			data.set({
					id : file.id,
					name : file.name,
					size : file.size,
					percent : file.percent,
					status : -1
				});
    		},
    		onFileUploaded: function(arg){
    			var file = arg.file;
    			var entity = data;
    			entity.set('percent', 100);
    			entity.set('status', file.status);
    		}
    	});
    	var button = new dorado.widget.SimpleIconButton({
    		id : buttonId,
    		action : uploadAction
    	});
    	return button;
    }
});


/** @Bind #gridFiles2.onCreate */
!function(self){
	self.set("&upload.renderer", new UploadCellRenderer());
};