jQuery Easyui datagrid editor為combobox時指定數(shù)據(jù)源實例
更新時間:2016年12月19日 14:46:48 作者:garfieldzf
當(dāng)在datagrid行內(nèi)部應(yīng)用添加編輯操作時,引入combobox是非常方便的操作,這篇文章主要介紹了jQuery Easyui datagrid editor為combobox時指定數(shù)據(jù)源實例,有興趣的可以了解一下。
當(dāng)在datagrid行內(nèi)部應(yīng)用添加編輯操作時,引入combobox是非常方便的操作,我在引入combobox時對數(shù)據(jù)源這快做個總結(jié),在做demo的過程中遇到個問題,就是當(dāng)你選擇了下拉框的值后點擊保存,此時顯示的是value值,而不是text值,這時使用格式化函數(shù)解決此問題。
var Address = [{ "value": "1", "text": "CHINA" }, { "value": "2", "text": "USA" }, { "value": "3", "text": "Koren" }];
function unitformatter(value, rowData, rowIndex) {
if (value == 0) {
return;
}
for (var i = 0; i < Address.length; i++) {
if (Address[i].value == value) {
return Address[i].text;
}
}
}
function GetTable() {
var editRow = undefined;
$("#Student_Table").datagrid({
height: 300,
width: 450,
title: '學(xué)生表',
collapsible: true,
singleSelect: true,
url: '/Home/StuList',
idField: 'ID',
columns: [[
{ field: 'ID', title: 'ID', width: 100 },
{ field: 'Name', title: '姓名', width: 100, editor: { type: 'text', options: { required: true } } },
{ field: 'Age', title: '年齡', width: 100, align: 'center', editor: { type: 'text', options: { required: true } } },
{ field: 'Address', title: '地址', width: 100, formatter: unitformatter, align: 'center', editor: { type: 'combobox', options: { data: Address, valueField: "value", textField: "text" } } }
]],
toolbar: [{
text: '添加', iconCls: 'icon-add', handler: function () {
if (editRow != undefined) {
$("#Student_Table").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
$("#Student_Table").datagrid('insertRow', {
index: 0,
row: {}
});
$("#Student_Table").datagrid('beginEdit', 0);
editRow = 0;
}
}
}, '-', {
text: '保存', iconCls: 'icon-save', handler: function () {
$("#Student_Table").datagrid('endEdit', editRow);
//如果調(diào)用acceptChanges(),使用getChanges()則獲取不到編輯和新增的數(shù)據(jù)。
//使用JSON序列化datarow對象,發(fā)送到后臺。
var rows = $("#Student_Table").datagrid('getChanges');
var rowstr = JSON.stringify(rows);
$.post('/Home/Create', rowstr, function (data) {
});
}
}, '-', {
text: '撤銷', iconCls: 'icon-redo', handler: function () {
editRow = undefined;
$("#Student_Table").datagrid('rejectChanges');
$("#Student_Table").datagrid('unselectAll');
}
}, '-', {
text: '刪除', iconCls: 'icon-remove', handler: function () {
var row = $("#Student_Table").datagrid('getSelections');
}
}, '-', {
text: '修改', iconCls: 'icon-edit', handler: function () {
var row = $("#Student_Table").datagrid('getSelected');
if (row != null) {
if (editRow != undefined) {
$("#Student_Table").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
var index = $("#Student_Table").datagrid('getRowIndex', row);
$("#Student_Table").datagrid('beginEdit', index);
editRow = index;
$("#Student_Table").datagrid('unselectAll');
}
} else {
}
}
}, '-', {
text: '上移', iconCls: 'icon-up', handler: function () {
MoveUp();
}
}, '-', {
text: '下移', iconCls: 'icon-down', handler: function () {
MoveDown();
}
}],
onAfterEdit: function (rowIndex, rowData, changes) {
editRow = undefined;
},
onDblClickRow: function (rowIndex, rowData) {
if (editRow != undefined) {
$("#Student_Table").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
$("#Student_Table").datagrid('beginEdit', rowIndex);
editRow = rowIndex;
}
},
onClickRow: function (rowIndex, rowData) {
if (editRow != undefined) {
$("#Student_Table").datagrid('endEdit', editRow);
}
}
});
}
效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Jquery Easyui進(jìn)度條組件Progress使用詳解(8)
- 如何解決jQuery EasyUI 已打開Tab重新加載問題
- jQuery Easyui datagrid行內(nèi)實現(xiàn)【添加】、【編輯】、【上移】、【下移】
- Jquery Easyui選項卡組件Tab使用詳解(10)
- Jquery Easyui菜單組件Menu使用詳解(15)
- Jquery Easyui自定義下拉框組件使用詳解(21)
- Jquery Easyui搜索框組件SearchBox使用詳解(19)
- jQuery Easyui 下拉樹組件combotree
- jQuery Easyui datagrid連續(xù)發(fā)送兩次請求問題
- 詳解Jquery Easyui的驗證擴(kuò)展
相關(guān)文章
jQuery.cookie.js使用方法及相關(guān)參數(shù)解釋
一個輕量級的cookie 插件,可以讀取、寫入、刪除 cookie。這篇文章主要介紹了jQuery.cookie.js使用方法及相關(guān)參數(shù)解釋,需要的朋友可以參考下2017-03-03
使用EVAL處理jqchart jquery 折線圖返回數(shù)據(jù)無效的解決辦法
eval函數(shù)可以把一些處理過程序代碼進(jìn)行解析從而達(dá)到可以執(zhí)行的一個狀態(tài),本篇文章給大家介紹使用eval處理jqchart jquery折線圖返回數(shù)據(jù)無效的解決辦法,對jqchart jquery相關(guān)內(nèi)容感興趣的朋友一起學(xué)習(xí)吧2015-11-11

