首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

求extjs 可编者grid

2013-07-08 
求extjs 可编辑grid谁还有自己做过可编辑GRID的例子,能添加新行,能初始化数据,例如其中一列是选择框,数据

求extjs 可编辑grid
谁还有自己做过可编辑GRID的例子,能添加新行,能初始化数据,例如其中一列是选择框,数据是从数据库获取过来的

麻烦各位了。
[解决办法]


    var sm = new Ext.grid.CheckboxSelectionModel(); // ext自带的CheckBox选择列
    var cm=new Ext.grid.ColumnModel([
    new Ext.grid.RowNumberer(),// 行号列
    sm,
    {
    header:"项目编号",
    dataIndex:"itemId",
    align:"center",
    width:80,
    sortable:true,
    editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlank:false}))
    },
    {
    header:"项目值",
    dataIndex:"itemValue",
    width:180,
    sortable:true,
    editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlank:false}))
    },
    {
    header:"排列顺序",
    dataIndex:"itemOrder",
    align:"center",
    width:80,
    sortable:true,
    editor:new Ext.grid.GridEditor(new Ext.form.TextField({allowBlank:false}))
    },
//    {
//    header:"是否有效",
//    dataIndex:"isLocked",
//    align:"center",
//    width:80,
//    sortable:true,
//    renderer:function(value){
//    return value ? "是" : "否";
//    }
////    ,
////    editor:new Ext.grid.GridEditor(new Ext.form.Checkbox({width:40,align:"center"}))
//    },
    {
    header:"项目说明",
    dataIndex:"itemRemark",
    width:240,
    sortable:true,
    editor:new Ext.grid.GridEditor(new Ext.form.TextField())
    },{
    dataIndex:"id",
    hidden:true
    },
    {
    dataIndex:"dictTypeId",
    hidden:true
    }
    ]);
    var gridpanel;
    //gridpanel头部工具栏
    var gridTbar = new Ext.Toolbar([{
        text : "新增",
        tooltip : "增加项目",
        icon : "../../pic/add-row.gif",
        handler : function() {
        if(dictTypeId==0){
        Ext.Msg.alert("提示","请先选择类别");


        }else{
        var initValue={
        id:"",
        dictTypeId:"",
        itemId:"",
        itemValue:"",
        itemOrder:"",
        isLocked:null,
        itemRemark:"",
        dictTypeId:dictTypeId
        };
        var item=new Ext.data.Record(initValue);
        gridpanel.stopEditing();
        ds.add(item);
        item.dirty=true;
        item.modified=initValue;
        if (gridpanel.getStore().modified.indexOf(item)==-1) {
        gridpanel.getStore().modified.push(item);
        }
        }
        }
    },"-",{
   text:"保存",
    tooltip:"保存操作",
    icon:"../../pic/update.gif",
    handler:function(){

    var modified=gridpanel.getStore().modified.slice(0);//得到修改过后的数据集合
    //将数据放到另一个数组中
    var jsonArray={};
    Ext.each(modified,function(m){
    if (m.data.itemId==""
[解决办法]
m.data.itemId==null
[解决办法]
m.data.itemValue==""
    
[解决办法]
m.data.itemValue==null
[解决办法]
m.data.itemOrder==""
[解决办法]
m.data.itemOrder==null) {
    Ext.Msg.alert("提示","请正确填写!");
    }else{
     Ext.Ajax.request({
    url:ctx()+"/spring/dic/save",
    method:"post",
    success:function(){
    Ext.Msg.alert("提示","保存成功!");
    ds.commitChanges();
    ds.load();
    },
    failure:function(){
    Ext.Msg.alert("提示","保存失败!");
    },
    params:{
    id:m.data.id,
    itemId:m.data.itemId,
    itemValue:m.data.itemValue,
    itemRemark:m.data.itemRemark,
    itemOrder:m.data.itemOrder,
    dictTypeId:m.data.dictTypeId,
    isLocked:m.data.isLocked
    }
    });


    }
    });
    }
    },"-",{
    text:"删除",
    tooltip:"删除项目",
    icon:"../../pic/delete.gif",
    handler:function(){
             if (sm.getCount() == 0) {
                Ext.MessageBox.alert("提示", "请选择要删除的行!");
            } else {
                var dictItem = sm.getSelected();

                Ext.Msg.confirm('提示', '您确定要删除吗?', function(button, text) {
                                    var ids = "";
                                    var records = gridpanel.getSelectionModel().getSelections();

                                    for (var i = 0; i < records.length; i++) {
                                        if (i == 0) {
                                            ids = records[0].data["id"];
                                        } else {
                                            ids += ',' + records[i].data["id"];
                                        }
                                    }
                                    if (button == 'yes') {
                                        Ext.Ajax.request({


                                                            url : ctx() + '/spring/dic/delete',
                                                            params : {
                                                                ids : ids
                                                            },
                                                            success : function() {
                                                                Ext.Msg.alert('提示', '删除成功!');
                                                                ds.remove(dictItem);
                                                                ds.reload();
                                                            },
                                                            failure : function() {
                                                                Ext.Msg.alert('提示', '删除失败!');


                                                            }
                                                        });
                                    }
                                });
            }
    }
    }]);
    var toolBar = new Ext.PagingToolbar({
                        pageSize : 15,
                        store : ds,
                        autoWidth : true,
                        displayInfo : true,
                        nextText : '下一页',
                        firstText : '第一页',
                        prevText : '上一页',
                        lastText : '末页',
                        displayMsg : "本页显示第{0}到{1}条的记录,一共有{2}条记录",
                        emptyMsg : "没有查询到相关的记录"
                    });

//       var centerpanel=new Ext.Panel({//中心部分
//   region:"center",
//bodyBorder : false,
//border:false
//   });
    gridpanel=new Ext.grid.EditorGridPanel({
   title:treetext,
   id:"typegrid",
//height:centerpanel.getHeight(),
//width:centerpanel.getWidth(),
   region:"center",
   cm:cm,
   sm:sm,
   tbar:gridTbar,
   bbar:toolBar,
   clicksToEdit: 1,
   autoEncode:true,
   ds:ds


   });



[解决办法]
http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/cell-editing.html
[解决办法]
单击编辑clicksToEdit: 1,
[解决办法]
3.0也支持
[解决办法]
可以
通过getCellEditor就可以找到是哪一行那一列的编辑控件
var operatorEditor = grid.colModel.getCellEditor(columnIndex, rowIndex);
[解决办法]
第一列的select事件也可以
[解决办法]
以前做过ext的可以编辑列表,写blog整理过完整的帖子,只是那会儿还是ext 1.3的版本。
EditPanel的实现
http://blog.csdn.net/Lisliefor/archive/2008/01/03/2012329.aspx

LZ可以参考一下,对照你那个版本的API,做出来问题不大。
[解决办法]
第二个问题:
单个删除的话,可以定义一个操作列,点击后,js方法中,ajax通过id删除数据,然后让store重新load一下。

热点排行