kendo.ui 框架 ,是一个非常不错的后台管理系统的前端框架.我使用的是免费版本v2013.2.918 .
下面进入正题,
做这个功能的目的: 客户可以根据自己设置要在grid 显示哪些字段,或哪些字段排在前面显示.
代码文件有三个:
1.前端数据交互到后台处理程序
2.css 样式设置
3 js 功能扩展文件
资源下载地址:http://download.csdn.net/detail/long5305350/8509505
代码:
JS 文件
/***
使用方法:$("#grid").kendoGrid({
custMenuSettings: {
enable: true,
settingUniqueID: "ASPRR" // 必须且唯一
}
})
*/
(function (window, factory) {
factory.call(window, kendo);
}(window,function (kendo) {
(function () {
$.extend(kendo.ui.Grid.fn.options, {
custMenuSettings: {
enable: false,
settingUniqueID: ""
}
});
var
kendoGrid = kendo.ui.Grid,
bqkendoGrid = kendo.ui.Widget.extend({
init: function (element, options) {
if (!options.custMenuSettings.enable) {
return new kendoGrid(element, options);
}
var
_gridMenuSetting = new gridMenuSetting(options, {
settingUniqueID: options.custMenuSettings.settingUniqueID
}),
grid = new kendoGrid(element, _gridMenuSetting.getGridOptions(options));
_gridMenuSetting.render(grid);
return grid;
},
options: {
name: "Grid"
}
});
kendo.ui.plugin(bqkendoGrid);
}());
var columnManager = kendo.Class.extend({
init: function (settingUniqueID) {
var that = this;
that.settingUniqueID = settingUniqueID;
},
options: {
readUrl: "?method=getColumnSetting", // 配置读取
saveUrl: "?method=saveColumnSetting" // 配置保存
},
getSettingData: function (fn, failfn, isAsync) {
var that = this, data = [];
failfn = failfn || function () { };
isAsync = isAsync == undefined ? true : isAsync;
$.ajax({
type: "POST",
url: that.options.readUrl,
data: {
settingUniqueID: that.settingUniqueID
},
dataType: "JSON",
async: isAsync
}).done(function (d) {
fn(d);
}).fail(function (e1, e2) {
alert("读取配置失败");
failfn();
});
},
saveSetting: function (data, fn) {
var that = this;
$.ajax({
type: "POST",
url: that.options.saveUrl,
data: {
settingUniqueID: that.settingUniqueID,
columnData: data
},
dataType: "JSON"
}).done(function (d) {
fn(d);
}).fail(function (d) {
alert("保存失败");
fn(d);
});
}
});
var gridMenuSetting = kendo.ui.Widget.extend({
init: function (gridOptions, options) {
var that = this,
container = that.container = $('
列名 | 是否显示 | 显示顺序 |