2017-12-25 114 views
6

मैं handsontable जेएस प्लगइन का उपयोग कर रहा हूं। मैं getCellMetaafterChange हुक लेकिन काम नहीं कर रहा हूं। जब मैं चेंज हुक के बाद फ़ंक्शन का उपयोग करता हूं, फ़ंक्शन काम कर रहा है। लेकिन चेंज हुक के बाद में काम नहीं कर रहा है।हैंडोंटेबल पर चेंज के बाद getCellMeta का उपयोग कैसे करें?

var container = document.getElementById('t1'), 
    options = document.querySelectorAll('.options input'), 
    table, 
    hot; 

hot = new Handsontable(container, {  
    autoWrapRow: true, 
    startRows: 81, 
    startCols: 206, 
    autoColumnSize : true, 
    stretchH: 'all', 
    afterChange : function(change,source) { 
     if (source === 'loadData') { 
     return; 
     } 
     var test = this.getCellMeta(change[0],change[1]); // not working, not return "id" meta 
     console.log(test); 
    } 
}); 

$.ajax({ 
    url: 'path', 
    type: 'GET', 
    dataType: 'json', 
    success: function (res) { 
    var data = [], row, pc = 0; 
    for (var i = 0, ilen = hot.countRows(); i < ilen; i++) 
    { 
     row = []; 
     for (var ii = 0; ii<hot.countCols(); ii++) 
     { 
     hot.setCellMeta(i,ii,'id',res[pc].id); 
     row[ii] = res[pc].price; 
     if(pc < (res.length-1)) { 

     pc++; 
     } 
     } 
     data[i] = row; 
    } 
    hot.loadData(data); 
    } 
}); 

var test = this.getCellMeta(0,0); // is working, return "id" meta 
console.log(test); 

आउटपुट कंसोल लॉग मैंने चेंज के बाद कोशिश की; enter image description here

आउटपुट कंसोल लॉग बाद में उपयोग करें; enter image description here

परिवर्तन के बाद सेल मेटा कैसे प्राप्त करें?

धन्यवाद।

+0

मैं इस प्लगइन से परिचित नहीं हूं लेकिन दस्तावेज़ केवल GetCellMeta और GetCellMeta के बाद दिखाता है; GetCellMeta कहां से आता है? – kshikama

+0

[लिंक] (https://image.prntscr.com/image/pSN__mN-RpCONgy_320krA.png) @ क्षीकामा –

उत्तर

3

आप बहुत करीब हैं, वहाँ सिर्फ अपने कॉलबैक में एक छोटी सी गलती है: doc for afterChange निर्दिष्ट करता है कि कॉलबैक का पहला तर्क (changes) है:

एक 2D सरणी संपादित कोशिकाओं में से प्रत्येक के बारे में जानकारी युक्त [[row, prop, oldVal, newVal], ...]

तो, प्रभावित कोशिका की पंक्तियां/स्तंभ की "मेटा" प्राप्त करने के लिए (यह मानते हुए वहाँ से एक है), तो आप उदाहरण के लिए this.getCellMeta(change[0][0],change[0][1]) कॉल करने के लिए की जरूरत है।

उदाहरण है कि परिवर्तन के पूरे सरणी पढ़ता है:

var hot = new Handsontable(container, { 
    /* rest of init... */ 
    afterChange : function(changes,source) { 
     console.log("Changes:", changes, source); 
     if (changes) { 
      changes.forEach(function(change) { 
       var test = hot.getCellMeta(change[0],change[1]); 
       console.log(test.id, test); // 'id' is the property you've added earlier with setMeta   
      }); 
     } 
    } 
}); 

देखें demo fiddle, खुले जे एस कंसोल, टेबल में कोई बदलाव (रों) बनाते हैं।

संबंधित मुद्दे