Show columns matching table headers
Show columns matching table headers
Greetings,
I have been using datatables for a while and in my opinion it's an amazing library. I would like to know if it's possible to change the behaviour of the filtering option. I have some data on the table headers () and I'm interested in showing only columns matching the information in these .
I've been playing a bit with the fnSetColumnVis but seems that it does not accept an array of ints in order to hide a specific range of columns.
Any help would be very appreciated.
Kind regards.
I have been using datatables for a while and in my opinion it's an amazing library. I would like to know if it's possible to change the behaviour of the filtering option. I have some data on the table headers () and I'm interested in showing only columns matching the information in these .
I've been playing a bit with the fnSetColumnVis but seems that it does not accept an array of ints in order to hide a specific range of columns.
Any help would be very appreciated.
Kind regards.
This discussion has been closed.
Replies
[code]
var names = [];
var indexes = [];
$('#tutorial-table thead tr a').each(function(i){
names.push($(this).text());
indexes.push(i);
});
$('#std_name').keyup(function(){
var arrayIndexes = [];
var keyword = this.value;
if(keyword !== ""){
$.each(names, function(i){
var rSearchTerm = new RegExp(keyword + '{1}', 'i');
if(names[i].match(rSearchTerm)){
arrayIndexes.push(i);
}
});
for(var i = 0; i < arrayIndexes.length; i++){
var index = arrayIndexes[i];
index += 1;
arrayIndexes[i] = index;
}
// we have to increment each index by one in order to avoid deleting the first row
// which contains all the headers data
// get the position we have to hide
var newArrayIndexes = arr_diff(indexes, arrayIndexes);
for(var i = 1; i < newArrayIndexes.length; i++){
oTable.fnSetColumnVis(parseInt(newArrayIndexes[i]), false);
}
[/code]
The code works well but as I said, in a table with 20 columns and 50 rows, it takes 0.6 seconds to delete one column, and this time adds up with every new column to be deleted.
Any ideas on how can I speed up this operation? (sorry for the crappy code, I'm still begining with JS!)