Reorder column index
Reorder column index
smassot
Posts: 28Questions: 9Answers: 1
Hello,
in my datatable I had to do a custom filter like that :
// définition des filtres datatables sur actions
['Total','Major','Partiel','Non','Retiré','Revu','Sans Objet','Indéfini'].forEach(function(action) {
var actionName = action.replace(' ','');
actionName = action.replace('é','e');
$.fn.DataTable.ext.search.push(
function( settings, data, dataIndex ) {
// console.info('trace:'+ data);
var actionValue = (data[6] == action);
return (actionValue ? $('#ckActions'+actionName).is(':checked') : $('#ckActions'+actionName).not(':checked'));
}
);
});
As you could see I check data[6] but now my customer would be able to reorder columns, I used colRerder plugin to do that
but when I reorder one or more colums, the initial data[6] is now for example col[3] and my custom filter didn't worked.
I'm not sure to have done my filter with the best way, could you tell me how I could know which new index had my data[6] after reorder please ?
Thanks a lot.
This discussion has been closed.
Answers
Generally speaking, when using ColReorder I would very much recommend using objects rather than arrays as this kind of issue is just side-stepped completely. If you do need to use arrays then you will need to either:
column-reorder
eventObjects are the way to go here if you can!
Allan
HI Allan,
totally agree with you for using object but I'm not totally skill about that,
Is there possible for you to let me one example on how to transform this code in object mode please ? thanks a lot.
Chris.
The key thing to do is so change your data source to use objects. If you are reading from the DOM then that is as simple as using
columns.data
- see this example.If you are using an Ajax data source, then you need to update whatever code you are using on the server-side to create objects rather than arrays.
Allan
here is data returned by ajax :
so I tried to use :
seems wrong, could you just give me one line example if you have time
Thanks a lot Allan
Actually that looks correct to me. I'm not sure why that wouldn't work. Can you link to a test case showing the issue please.
Allan
Well i's difficult to do a test case, cause there are many function in order to make this work :/
What I could see with a console.log(data) :
trace:12 - Comment garantissons-nous la dignité des résidents (en particulier, comment traitons-nous son linge personnel et la question de son habillement) ?,Evaluation interne 2015, Réorganisation du travail des remplacants en lingerie,ASH REF,Dir, Lingéres, ASHREF,31-08-2015,Non,Dédier et former des personnels en remplacement,t ,,Zero plainte ,Protocoles et plannings,,Non,
So, it seems to be juste one date line without any column name information. Maybe I do it wrong ?
I'm afraid I don't know what is wrong without being ale to see the full code. I don't know what
data
is in your one line above for example. A link to a test case would let me take a look and see what is happening.Allan
I will try to do a test case if possible. Thanks Allan