Get column's position by its label

Hello,

I have some function based on the initial position number of a column in afterChange callBack.
So the problem is, when i move the column the order is automaticly different so my function in afterChange doesn’t work anymore… So i wonder if there is a way to get the position number of a column by its label ?

I hope it’s understable,

Thank’s by advance,

Cordially

Hi @tanguy.belin

it should be possible if your data is an object. Then you just ask for the key. Can you share a piece of logic that you use to related the data in the afterChange hook?

Hi @aleksandra_budnik,

Thanks for your awnser, this is a piece of afterChange hook :

 afterChange: function(src, changes){
            if(changes !== 'loadData'){
                dataRow = this.getDataAtRow(src[0][0]);
                changeMethod = "update";
            }
            //autocomplete field from preponderance table
            if(src !== null) {
                designation = src[0][3];
                console.log(frontTire + "==>" + src[0][1]);
                if(src[0][1] === 3) {
                    if(!change) {
                        change = true;
                        tireData = $.getValues(src[0][3]);
                        if (designation.indexOf("TL") >= 0) {
                            designation = src[0][3].replace('TL', '');
                        }
                        if (designation.indexOf("IND") >= 0) {
                            designation = src[0][3].replace('IND', '');
                        }
                        if(designation.indexOf("CFO") >= 0 || designation.indexOf("CFO+") >= 0 || designation.indexOf("IMP") >= 0) {
                            split2 = designation.split(' ');
                            split2 = jQuery.grep(split2, function(n){ return (n); });
                            hot.setDataAtCell(src[0][0], 3, split2[0] + ' ' + split2[1] + ' ' + split2[2] + ' ' + split2[3]);
                            hot.setDataAtCell(src[0][0], 4, split2[4]);
                        } else {
                            split2 = designation.split(' ');
                            split2 = jQuery.grep(split2, function(n){ return (n); });
                            if (split2.length == 4) {
                                hot.setDataAtCell(src[0][0], 3, split2[0] + ' ' + split2[1] + ' ' + split2[2]);
                                hot.setDataAtCell(src[0][0], 4, split2[3]);
                            } else if(split2.length == 3 || split2.length == 2) {
                                hot.setDataAtCell(src[0][0], 3, split2[0] + ' ' + split2[1]);
                                hot.setDataAtCell(src[0][0], 4, split2[2]);
                            }
                        }

                        if(tireData[0]) {
                            hot.setDataAtCell(src[0][0], 5, tireData[0]['gamme']);
                            hot.setDataAtCell(src[0][0], 6, tireData[0]['marque']);
                            hot.setDataAtCell(src[0][0], 12, tireData[0]['circonferenceRoulement']);
                            hot.setDataAtCell(src[0][0], 15, tireData[0]['cai']);
                        }

                    } else {
                        change = false;
                    }
                }

Thank you,

Hi @tanguy.belin

I think that you can use the afterColumnMove hook and the colToProp method to get keys for moved columns. Here’s a demo http://jsfiddle.net/ug98nLwt/
Let me know if that helps or we should find something else or more.