// 定义拖动时样式 function change(val){ if(val > 0){ return '<span style="color:green;" mce_style="color:green;">' + val + '</span>'; }else if(val < 0){ return '<span style="color:red;" mce_style="color:red;">' + val + '</span>'; } return val; } // 定义拖动时样式 function pctChange(val){ if(val > 0){ return '<span style="color:green;" mce_style="color:green;">' + val + '%</span>'; }else if(val < 0){ return '<span style="color:red;" mce_style="color:red;">' + val + '%</span>'; } return val; } var sm2 = new Ext.grid.RowSelectionModel({singleSelect: true}); var cm = new Ext.grid.ColumnModel([sm2, { id:'id', width: "10%", dataIndex:"id" }, { id:'name', width: 220, dataIndex:"name", header:"分类名" }, { id:'state', dataIndex:"state", header:"是否启用" },{ id:'type', dataIndex:"type", header:"分类类型" } ]); // gridpanel var grid = new Ext.grid.GridPanel({ iconCls:'icon-grid', frame:true, renderTo:Ext.get("divgrid"), cm:cm, sm: sm2, enableDragDrop: true, dropConfig: { appendOnly:true }, ddGroup: "GridDD", store:store, buttons: [{text:'Save'},{text:'Cancel'}], buttonAlign:'center' }); //拖动排序必须的代码 var ddrow = new Ext.dd.DropTarget(grid.getEl(), { ddGroup: "GridDD", // Data come from // copy:true, notifyDrop : function(dd, e, data){ var rows=grid.getSelectionModel().getSelections(); var count = rows.length; var cindex=dd.getDragData(e).rowIndex; var array=[]; for(var i=0;i<count;i++){ var index = cindex+i; array.push(index); } store.remove(store.getById( data.selections[0].id)); store.insert(cindex,data.selections); grid.getView().refresh(); grid.getSelectionModel().selectRows(array); } }); // 传到后台排序的数据 function getSortIndexDate(store) { var resultNode =[]; var length = store.getCount(); for (var i = 0; i < length; i++) { resultNode[i] = { id: store.getAt(i).id, sortIndex:store.getAt(i).data.index }; } var encNodes = Ext.encode(resultNode); return encNodes; }