国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery Easyui datagrid editor為combobox時指定數(shù)據(jù)源實例

2019-11-19 18:23:22
字體:
供稿:網(wǎng)友

當在datagrid行內(nèi)部應(yīng)用添加編輯操作時,引入combobox是非常方便的操作,我在引入combobox時對數(shù)據(jù)源這快做個總結(jié),在做demo的過程中遇到個問題,就是當你選擇了下拉框的值后點擊保存,此時顯示的是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: '學生表',    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)容,希望對大家的學習有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 东莞市| 武汉市| 京山县| 余庆县| 瑞昌市| 清河县| 郎溪县| 泰兴市| 枣庄市| 章丘市| 远安县| 资溪县| 辽宁省| 会泽县| 上犹县| 北碚区| 肇东市| 错那县| 呼和浩特市| 翁源县| 白山市| 平谷区| 社旗县| 太白县| 宝清县| 双牌县| 奎屯市| 沁源县| 东海县| 嵊州市| 英德市| 辰溪县| 嵊州市| 行唐县| 融水| 廊坊市| 武山县| 顺义区| 无棣县| 博野县| 贵港市|