1. 程式人生 > >gridpanel中拖拽排序

gridpanel中拖拽排序

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->// 定義拖動時樣式function change(val){
        
if(val >0){
            
return'<span style="color:green;">'+ val +'</span>';
        }
elseif(val <0){
            
return'<span style="color:red;">'+ val +'</span>';
        }
        
return val;
    }

    
// 定義拖動時樣式function pctChange(val){
        
if(val >0){
            
return'<span style="color:green;">'+ val +'%</span>';
        }
elseif(val <0){
            
return'<span 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;
        }
hello