ExtJS

2012-01-03 9 views
5

में ग्रिड पंक्ति को हाइलाइट करना/चुनना मैं एक्सएस जेएस के लिए नौसिखिया हूं। मैं एक ग्रिड पैनल पर काम कर रहा हूं जिसमें जब मैं किसी भी पंक्ति का चयन/क्लिक करता हूं, तो चयनित पंक्ति से संबंधित कुछ डेटा ग्रिड के नीचे पैनल में प्रदर्शित होता है। साथ ही जब विंडो लोड हो जाती है तो पहले डिफ़ॉल्ट रूप से चयनित/हाइलाइट किया जाना चाहिए। वर्तमान में ग्रिड & पैनल ठीक से प्रदर्शित होता है। यहां तक ​​कि चयनित पंक्ति से संबंधित डेटा पैनल में प्रदर्शित होता है लेकिन पंक्ति को हाइलाइट नहीं किया जा रहा है। मैंने grid.focusRow(0) & grid.getRow(0).highlight() विधियों का प्रयास किया है लेकिन वे काम नहीं कर रहे हैं। नीचे मेरा कोड है।ExtJS

//the js file code 
initComponent : function() { //within the window instance 

    var single = false; 
    var store = new Ext.data.XmlStore({//all necessary fields added}); //store 
    HttpUtil.syncCall(this.url, "GET", this.loadStore, store,this); 
    var acctTplMarkup = [//the fields here are displayed on row selection ]; 
       /*The template for displaying the details of the selected row */ 
       this.acctTpl = new Ext.Template(acctTplMarkup); 
    //check for request type, if type is range of checks create the grid 
    if (single == false) { 
     var gridView = new Ext.grid.GridView(); 
     var colModel = new Ext.grid.ColumnModel([ { 
      header : 'Status', 
      dataIndex : 'status' 
     }, { 
      header : 'Message', 
      dataIndex : 'message' 
     } ]); 
     var selModel = new Ext.grid.RowSelectionModel({ 
      singleSelect : true 
     }); 
     grid = new Ext.grid.GridPanel({ 
              ... 
         listeners : { 
       render : function(grid) { 
        Ext.getCmp('check').store.on('load',function(store, records, options) { //check is the id value for the window instance 
         grid.getSelectionModel().selectFirstRow(); 
        }); 
       } 
      } 
    }); //gridPanel 
    } //if 
    /* If request type is range select then display the grid */ 
       ... 
    if (single == false) { 
    grid.getSelectionModel().on('rowselect', function(sm, rowIdx, r) { 
Ext.getCmp('check').acctTpl.overwrite(Ext.getCmp('detailPanel').body, r.data); 
     }); //rowselect 
    } //if 

    Ext.apply(this, { 
            ... 
      listeners : { 
      'afterrender' : function(){ 
      Ext.getCmp('check').acctTpl.overwrite(Ext.getCmp('detailPanel').body, this.store.getAt(0).data,true); 
      } 
     } 
    }); 
    Check.superclass.initComponent.apply(this, arguments); 

}, //initComponent 

डेटास्टोर से डेटा लोड किया जाता है & ठीक से प्रदर्शित लेकिन सिर्फ पंक्ति पर प्रकाश डाला नहीं है। क्या कोई मुझे बता सकता है कि मैं गलत कहां गया?

उत्तर

10

Ext.grid.GridPanel में कोई getRow विधि नहीं है। हालांकि, Ext.grid.GridView में से एक है।

पंक्ति आप निम्न करना चाहिए पर प्रकाश डाला करने के लिए:

var row = grid.getView().getRow(0); // Getting HtmlElement here 
Ext.get(row).highlight(); // Getting element wrapper and using its "highlight" method 

पंक्ति चयन करने के लिए आप ग्रिड के SelectionModel उपयोग कर रहे हैं:

grid.getSelectionModel().selectRow(0) 
+0

अरे आपकी प्रतिक्रिया के लिए धन्यवाद। मैंने पहले से ही उन तरीकों का प्रयास किया है लेकिन वे काम नहीं कर रहे हैं। मेरा ग्रिड पूरा हो गया है लेकिन किसी भी तरह से मैं पहली पंक्ति को हाइलाइट नहीं कर सकता। क्या कोई और तरीका है? –

+0

क्या आपको उल्लिखित विधियों के साथ कोई त्रुटि मिल रही है? सभी कामकाज संभवतः आपको भविष्य में अतिरिक्त समस्याएं लाएंगे, इसलिए आप स्व-निर्मित कुछ भी करने से पहले मौजूदा तरीके से काम करने की कोशिश करेंगे। – Li0liQ

+2

'getView()। GetRow' ExtJS 4 में मौजूद नहीं है; 'getView()। getNode' का उपयोग करें। –

1

एक विशेष सूचकांक में एक पंक्ति का चयन करने के लिए, चयन का उपयोग करें आदर्श।

Ext.grid.GridPanel.getView().getSelectionModel().select(index); 
6

घटक: Ext.grid.Panel

संस्करण: 4.0.0

एक आइटम चुनें और पिछले चयन निकालने के लिए:

grid.getSelectionModel().select(0); 

एक चुनने के लिए आइटम और पिछले चयन रखें:

grid.getSelectionModel().select(0, true); 
+0

ग्रेट :) यह मेरे लिए अच्छा काम करता है :) –