ColumnFilter :: works only on last dataTable when created in a function
ColumnFilter :: works only on last dataTable when created in a function
There is a re-entrance problem in columnFilter. A global var (oTable) is used and take the value of the last columnFilter objet created. This happen when a function is used to create all the dataTables.
I got this problem and resolve it by the following way.
[quote]Edit : jquery.dataTables.columnFilter.js[/quote]
I add a function :
[code]
function oTable_get (o) {
idTable = $(o).parents('table:eq(0)').attr('id');
return $("#"+idTable).dataTable();
}
// just before
function fnCreateInput(regex, smart, bIsNumber) {
[/code]
and add the call in events functions.
[code]
if (bIsNumber && !oTable.fnSettings().oFeatures.bServerSide) {
input.keyup(function () {
oTable = oTable_get(this); // added
/* Filter on the column all numbers that starts with the entered value */
oTable.fnFilter('^' + this.value, index, true, false);
});
} else {
input.keyup(function () {
oTable = oTable_get(this); // added
/* Filter on the column (the index) of this element */
oTable.fnFilter(this.value, index, regex, smart);
});
}
input.focus(function () {
if ($(this).hasClass("search_init")) {
oTable = oTable_get(this); // added
$(this).removeClass("search_init");
this.value = "";
}
});
input.blur(function () {
oTable = oTable_get(this); // added
if (this.value == "") {
$(this).addClass("search_init");
this.value = asInitVals[index];
}
});
[/code]
It works now for me. (sry for my English)
I got this problem and resolve it by the following way.
[quote]Edit : jquery.dataTables.columnFilter.js[/quote]
I add a function :
[code]
function oTable_get (o) {
idTable = $(o).parents('table:eq(0)').attr('id');
return $("#"+idTable).dataTable();
}
// just before
function fnCreateInput(regex, smart, bIsNumber) {
[/code]
and add the call in events functions.
[code]
if (bIsNumber && !oTable.fnSettings().oFeatures.bServerSide) {
input.keyup(function () {
oTable = oTable_get(this); // added
/* Filter on the column all numbers that starts with the entered value */
oTable.fnFilter('^' + this.value, index, true, false);
});
} else {
input.keyup(function () {
oTable = oTable_get(this); // added
/* Filter on the column (the index) of this element */
oTable.fnFilter(this.value, index, regex, smart);
});
}
input.focus(function () {
if ($(this).hasClass("search_init")) {
oTable = oTable_get(this); // added
$(this).removeClass("search_init");
this.value = "";
}
});
input.blur(function () {
oTable = oTable_get(this); // added
if (this.value == "") {
$(this).addClass("search_init");
this.value = asInitVals[index];
}
});
[/code]
It works now for me. (sry for my English)
This discussion has been closed.