Find Index of Column(s) after it has been Moved

I have a table and each columns (has filter/dropdown) are allocated an id eg. fac, date, sel, loc, tag … etc

We have hard coded the index of columns to set and get the cookie elsewhere.

[code]function doInitGrid(){

mygrid.setColumnIds(“fac,date,sel,loc,tag”); //set ids
mygrid.attachEvent(“onFilterStart”,function(ind,data)
{
setCookie(“Tray_fac_filter”,mygrid.getFilterElement(0).value,365); //column index 0
setCookie(“Tray_loc_filter”,mygrid.getFilterElement(3).value,365);//column index 3
setCookie(“Tray_tag_filter”,mygrid.getFilterElement(4).value,365); //column index 4

mygrid.getFilterElement(0).value = getCookie(“Tray_fac_filter”)
mygrid.getFilterElement(3).value = getCookie(“Tray_dep_filter”)
mygrid.getFilterElement(4).value = getCookie(“Tray_prg_filter”)
});
}[/code]

But when the columns are moved, the problem arises as the index of the column changes yet it is set in setCookie /getCoookie

DHTMLX allows to get the index of the id using –

var colInd = grid.getColIndexById(id); eg: var colInd = grid.getColIndexById(date); // outputs 1. After moving the date column to the end -- fac, sel, loc, tag, date // it will output 4.
However, we have about 14 columns that can be moved/rearranged and I could use the

[code]var colInd = grid.getColIndexById(id); 15 times

var facInd = grid.getColIndexById(“fac”);
var dateInd = grid.getColIndexById(“date”);
var selInd = grid.getColIndexById(“sel”);
var locInd = grid.getColIndexById(“loc”;
var tagInd = grid.getColIndexById(“tag”);[/code]

and put those variables in the set/get cookie. I was thinking if there was a better way.

To understand the code better, I have put the minimised version of the code in fiddle.

jsfiddle.net/19eggs/s5myW/2/

Unfortunately the getting the id from the index or index from the id is the only available way.