欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

easyuidatagrid单元格赋值方法

程序员文章站 2022-11-20 14:19:22
easyuidatagrid单元格赋值方法。 var EasyUIDataGrid = { //设置列的值(适用于所有列) setFieldValue: function (...
easyuidatagrid单元格赋值方法。
var EasyUIDataGrid = {
//设置列的值(适用于所有列)
setFieldValue: function (fieldName, value, index, grid) {
if (grid == undefined || grid == '') {
grid = $('#editgrid');
}


if (index == undefined || index == '') {
index = this.GeteditIndex(grid);
if (index == undefined) {
index = 0;
}
}
var row = grid.datagrid('getRows')[index];
if (row != null) {
var editor = grid.datagrid('getEditor', { index: index, field: fieldName });
if (editor != null) {
this.setValueToEditor(editor, value);
}
else {
var view = $('.datagrid-view');
for (var i = 0; i < view.length; i++) {
if ($(view[i]).children(grid.selector).length > 0) {
var view = $(view[i]).children('.datagrid-view2');
var td = $(view).find('.datagrid-body td[field="' + fieldName + '"]')[index]
var p = $(td).find('p')[0];
$(p).text(value);
}
}


row[fieldName] = value;
}
grid.datagrid('clearSelections');
}
},


//设置datagrid的编辑器的值
setValueToEditor: function (editor, value) {
switch (editor.type) {
case "combobox":
editor.target.combobox("setValue", value);
break;
case "combotree":
editor.target.combotree("setValue", value);
break;
case "textbox":
editor.target.textbox("setValue", value);
break;
case "numberbox":
editor.target.numberbox("setValue", value);
break;
case "datebox":
editor.target.datebox("setValue", value);
break;
case "datetimebox":
editor.target.datebox("setValue", value);easyuidatagrid单元格赋值方法。

var EasyUIDataGrid = {

//设置列的值(适用于所有列)

setFieldValue: function (fieldName, value, index, grid) {

if (grid == undefined || grid == '') {

grid = $('#editgrid');

}

if (index == undefined || index == '') {

index = this.GeteditIndex(grid);

if (index == undefined) {

index = 0;

}

}

var row = grid.datagrid('getRows')[index];

if (row != null) {

var editor = grid.datagrid('getEditor', { index: index, field: fieldName });

if (editor != null) {

this.setValueToEditor(editor, value);

}

else {

var view = $('.datagrid-view');

for (var i = 0; i < view.length; i++) {

if ($(view[i]).children(grid.selector).length > 0) {

var view = $(view[i]).children('.datagrid-view2');

var td = $(view).find('.datagrid-body td[field="' + fieldName + '"]')[index]

var p = $(td).find('p')[0];

$(p).text(value);

}

}

row[fieldName] = value;

}

grid.datagrid('clearSelections');

}

},

//设置datagrid的编辑器的值

setValueToEditor: function (editor, value) {

switch (editor.type) {

case "combobox":

editor.target.combobox("setValue", value);

break;

case "combotree":

editor.target.combotree("setValue", value);

break;

case "textbox":

editor.target.textbox("setValue", value);

break;

case "numberbox":

editor.target.numberbox("setValue", value);

break;

case "datebox":

editor.target.datebox("setValue", value);

break;

case "datetimebox":

editor.target.datebox("setValue", value);

break;

default:

editor.html = value;

break;

}

}

}

break;
default:
editor.html = value;
break;
}
}
}