1. 程式人生 > >easyui datagrid 編輯行繫結combogrid並實現下拉賦值

easyui datagrid 編輯行繫結combogrid並實現下拉賦值

1.第一步初始化

$.extend($.fn.datagrid.defaults.editors, {
            combogrid: {
                init: function (container, options) {
                    var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container);
                    input.combogrid(options);
                    return input;
                },
                destroy: function (target) {
                    $(target).combogrid('destroy');
                },
                getValue: function (target) {
                    return $(target).combogrid('getValue');
                },
                setValue: function (target, value) {
                    $(target).combogrid('setValue', value);
                },
                resize: function (target, width) {
                    $(target).combogrid('resize', width);
                }
            }
        });

2.第二步

{
                          width: '120',
                          title: '產品編碼',
                          sortable: true,
                          field: 'productid',
                          editor: {
                              type: 'combogrid',
                              options:
                              {
                                  panelWidth: 800,
                                  idField: 'newcode',
                                  textField: 'newcode',
                                  delay: 1000,
                                  mode: 'remote',
                                  url: '../Ajax/ProfitCenter/LoadProjectCode.ashx?guid=' + Math.random() + '',
                                  frozenColumns:
                                  [[
                                  {
                                      width: '100',
                                      title: '產品編號',
                                      field: 'newcode'
                                  },
                                  {
                                      width: '160',
                                      title: '產品描述',
                                      field: 'productnamess'
                                  }
                                  ,
                                     { width: '80', title: '貨物型別', field: 'stocktyname' }]],
                                  columns:
                                  [[
                                     { field: 'warehousename', title: '倉庫', width: 100 },
                                     { field: 'quantitynow', title: '預留數量', width: 80 },
                                     { field: 'realqty', title: '可用庫存', width: 80 },
                                     { field: 'brandname', title: '品牌', width: 100 },
                                     { field: 'classname', title: '產品型別', width: 100 },
                                     { field: 'statusname', title: '產品狀態', width: 100 }
                                  ]], onSelect: function (rowIndex, rowData) {
                                        var productname = $('#listEditGrid').datagrid('getEditor', { index: editflag, field: 'productname' });
                                        var stocktypeid = $('#listEditGrid').datagrid('getEditor', { index: editflag, field: 'stocktypeid' });
                                        var productid = $('#listEditGrid').datagrid('getEditor', { index: editflag, field: 'pid' });
                                        var productattributeid = $('#listEditGrid').datagrid('getEditor', { index: editflag, field: 'productattributeid' });
                                        var stocktypename = $('#listEditGrid').datagrid('getEditor', { index: editflag, field: 'stocktypename' });
                                        var outqty = $('#listEditGrid').datagrid('getEditor', { index: editflag, field: 'qq' });
                                                  $(productname.target).val(rowData.productnamess); //賦值
                                                  $(stocktypeid.target).val(rowData.stocktypeid); //賦值
                                                  $(productid.target).val(rowData.productid); //賦值產品ID
                                                  $(productattributeid.target).val(rowData.productattributeid);
                                                  $(stocktypename.target).val(rowData.stocktyname);
                                                  $(productname.target).attr("disabled", "disabled");
                                                  $(stocktypename.target).attr("disabled", "disabled");
                                          });
                                      }
                                  }
                              }
                          }
                              
                      }