1. 程式人生 > >給Grid動態添加列和添加樣式

給Grid動態添加列和添加樣式

geb project idt 選中 center itl check actual plus

BudgetProjectSearch: function () {
$("#load").show();
var that = this;
var postmodel = {};
postmodel.year = that.YearStr;
postmodel.month = that.monthvalue;
//獲取所有選中的節點
var nodes = $("#tree").data("kendoTreeView").dataSource.view();
var checkedNodes = [];
checkedNodeIds(nodes, checkedNodes);
postmodel.OrgData = checkedNodes;
postmodel.selectedExpenseItemIdStr = that.selectedExpenseItemIdStr;
if (postmodel.OrgData.length == 0) {
$("#load").hide();
messageBox.show({ message: "請選擇部門" }, "info");
}
else if (postmodel.selectedExpenseItemIdStr.length == 0) {
$("#load").hide();
messageBox.show({ message: "請選擇費用項目" }, "info");
}
else if (postmodel.year == null || postmodel.year == "") {
$("#load").hide();
messageBox.show({ message: "請選擇年份" }, "info");
}
else if (postmodel.month == null || postmodel.month == "") {
$("#load").hide();
messageBox.show({ message: "請選擇月份" }, "info");
}
else {
$.post("/Reports/CompanyReport/GetBudgetActualAchievementList", postmodel, function (r) {
$("#load").hide();
if (r.status == 202) {
messageBox.show({ message: r.msg }, "info");
}
else {
//根據費用項目初始化filed
var columns = [];
columns.push({
field: "EmployeeName",
title: "名稱",
width: 400
});
columns.push({
field: "AllTotolBuget",
title: "全年合計預算",
attributes: { class: ‘center‘ },
width: 150
});
for (var i = 1; i <= postmodel.month; i++) {
if (i == 1) {
columns.push({
field: "Actual01",
title: "1月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 2) {
columns.push({
field: "Actual02",
title: "2月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 3) {
columns.push({
field: "Actual03",
title: "3月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 4) {
columns.push({
field: "Actual04",
title: "4月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 5) {
columns.push({
field: "Actual05",
title: "5月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 6) {
columns.push({
field: "Actual06",
title: "6月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 7) {
columns.push({
field: "Actual07",
title: "7月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 8) {
columns.push({
field: "Actual08",
title: "8月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 9) {
columns.push({
field: "Actual09",
title: "9月",
attributes: { class: ‘center‘ },
width: 100
});
} if (i == 10) {
columns.push({
field: "Actual10",
title: "10月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 11) {
columns.push({
field: "Actual11",
title: "11月",
attributes: { class: ‘center‘ },
width: 100
});
}
if (i == 12) {
columns.push({
field: "Actual12",
title: "12月",
attributes: { class: ‘center‘ },
width: 100
});
}

}
columns.push({
field: "ActualTotol",
title: "報銷合計",
attributes: { class: ‘center‘ },
width: 100
});
columns.push({
field: "BugetTotol",
title: "實際發生月預算合計",
attributes: { class: ‘center‘ },
width: 200
});
columns.push({
field: "difference",
title: "差異",
attributes: { class: ‘center‘ },
width: 100
});
columns.push({
field: "AllSurplusBuget",
title: "全年剩余預算",
attributes: { class: ‘center‘ },
width: 150
});
var grid = $("#grid").data("kendoGrid");
grid.setOptions({
columns: columns
});
var dataSource = new kendo.data.DataSource({
data: JSON.parse(r.data),
//pageSize: 15,
});
grid.setDataSource(dataSource);
grid.dataSource.page(1);

debugger
if (grid.dataSource != null) {
if (grid.dataSource.data().length > 0) {
_.each(grid.dataSource.data(), function (data) {
if (data.IsOrgTotol == "1") {


$("[data-uid=‘" + data.uid + "‘]").css("background-color", "#FFC0CB");
}
if (data.IsOrgTotol == "2") {
$("[data-uid=‘" + data.uid + "‘]").css("background-color", "#F58220");
}
})
}
}
}
});
}
},

給Grid動態添加列和添加樣式