jQuery Easyui datagrid editor為combobox時(shí)指定數(shù)據(jù)源實(shí)例
當(dāng)在datagrid行內(nèi)部應(yīng)用添加編輯操作時(shí),引入combobox是非常方便的操作,我在引入combobox時(shí)對數(shù)據(jù)源這快做個(gè)總結(jié),在做demo的過程中遇到個(gè)問題,就是當(dāng)你選擇了下拉框的值后點(diǎn)擊保存,此時(shí)顯示的是value值,而不是text值,這時(shí)使用格式化函數(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ā)送到后臺(tái)。 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)實(shí)現(xiàn)【添加】、【編輯】、【上移】、【下移】
- Jquery Easyui選項(xiàng)卡組件Tab使用詳解(10)
- Jquery Easyui菜單組件Menu使用詳解(15)
- Jquery Easyui自定義下拉框組件使用詳解(21)
- Jquery Easyui搜索框組件SearchBox使用詳解(19)
- jQuery Easyui 下拉樹組件combotree
- jQuery Easyui datagrid連續(xù)發(fā)送兩次請求問題
- 詳解Jquery Easyui的驗(yàn)證擴(kuò)展
相關(guān)文章
整理8個(gè)很棒的 jQuery 倒計(jì)時(shí)插件和教程
jQuery 是最流行也是使用最廣泛的 JavaScript 框架,它簡化了 HTML 文檔操作,事件處理,動(dòng)畫效果和 Ajax 交互。下面向大家分享8個(gè)優(yōu)秀的 jQuery 倒計(jì)時(shí)插件和教程2011-12-12jQuery.cookie.js使用方法及相關(guān)參數(shù)解釋
一個(gè)輕量級的cookie 插件,可以讀取、寫入、刪除 cookie。這篇文章主要介紹了jQuery.cookie.js使用方法及相關(guān)參數(shù)解釋,需要的朋友可以參考下2017-03-03使用EVAL處理jqchart jquery 折線圖返回?cái)?shù)據(jù)無效的解決辦法
eval函數(shù)可以把一些處理過程序代碼進(jìn)行解析從而達(dá)到可以執(zhí)行的一個(gè)狀態(tài),本篇文章給大家介紹使用eval處理jqchart jquery折線圖返回?cái)?shù)據(jù)無效的解決辦法,對jqchart jquery相關(guān)內(nèi)容感興趣的朋友一起學(xué)習(xí)吧2015-11-11jquery控制左右箭頭滾動(dòng)圖片列表的實(shí)例
jquery控制左右箭頭滾動(dòng)圖片列表的實(shí)例,需要的朋友可以參考一下2013-05-05jQuery Div中加載其他頁面的實(shí)現(xiàn)代碼
在做一個(gè)表單簽核系統(tǒng)時(shí),需在要簽核頁面中將表單內(nèi)容(事先做好的PHP頁面)顯示出來,于就是想能不能利用Ajax技術(shù)把這個(gè)事先做好的頁面嵌入到簽核頁面中呢?2009-02-02