一、获取datagrid的列的title和field
var printDatagrid = $("#GoodsList");
var frozenColumns = printDatagrid.datagrid("options").frozenColumns; // 得到frozenColumns对象
var columns = printDatagrid.datagrid("options").columns; // 得到columns对象
var columnList = new Array();
if (typeof columns != 'undefined' && columns != '') {
$(columns).each(function (index) {
if (typeof frozenColumns != 'undefined' && typeof frozenColumns[index] != 'undefined') {
for (var i = 0; i < frozenColumns[index].length; ++i) {
if (!frozenColumns[index][i].hidden) {
var column = {};
column["title"] = columns[0][i].title;
column["field"] = columns[0][i].field;
columnList.push(column);
}
}
}
for (var i = 0; i < columns[index].length; ++i) {
if (!columns[index][i].hidden) {
var column = {};
column["title"] = columns[0][i].title;
column["field"] = columns[0][i].field;
columnList.push(column);
}
}
})
}
var column1 = {};
column1["title"] = "Atitle";
column1["field"] = "Afield";
columnList.splice(0, 0, column1);//新增一个对象到第一位
columnList.splice(-1, 1);//删除最后一个对象