Upgrading from 1.8 -> 1.9 "issues"

Upgrading from 1.8 -> 1.9 "issues"

RomainRomain Posts: 2Questions: 0Answers: 0
edited February 2012 in DataTables 1.9
Hi Allan,

To begin, i wanna to thank you for your really great job for datatables =)

I wanna upgrade from 1.8 to 1.9, and i have noticed that the "highlight search function" found in this forum is broken (without any error in the javascript console).

The code here:

[code]
// HIGHLIGHT FCT
jQuery.fn.dataTableExt.oApi.fnSearchHighlighting = function(oSettings) {
// Initialize regex cache
oSettings.oPreviousSearch.oSearchCaches = {}
oSettings.fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull) {
// Initialize search string array
var searchStrings = [];
var oApi = this.oApi;
var cache = oSettings.oPreviousSearch.oSearchCaches;
// Global search string
// If there is a global search string, add it to the search string array
if (oSettings.oPreviousSearch.sSearch) {
searchStrings.push(oSettings.oPreviousSearch.sSearch);
}
// Individual column search option object
// If there are individual column search strings, add them to the search string array
if ((oSettings.aoPreSearchCols) && (oSettings.aoPreSearchCols.length > 0)) {
for (i in oSettings.aoPreSearchCols) {
if (oSettings.aoPreSearchCols[i].sSearch) {
searchStrings.push(oSettings.aoPreSearchCols[i].sSearch);
}
}
}
// Create the regex built from one or more search string and cache as necessary
if (searchStrings.length > 0) {
var sSregex = searchStrings.join("|");
if (!cache[sSregex]) {
// This regex will avoid in HTML matches
cache[sSregex] = new RegExp("("+sSregex+")(?!([^<]+)?>)", 'i');
}
var regex = cache[sSregex];
}
// Loop through the rows/fields for matches
$('td', nRow).each( function(i) {
// Take into account that ColVis may be in use
var j = oApi._fnVisibleToColumnIndex( oSettings,i);
// Only try to highlight if the cell is not empty or null
if (aData[j]) {
// If there is a search string try to match
if ((typeof sSregex !== 'undefined') && (sSregex)) {
this.innerHTML = aData[j].replace( regex, function(matched) {
return ""+matched+"";
});
}
// Otherwise reset to a clean string
else {
this.innerHTML = aData[j];
}
}
});
return nRow;
};
return this;
}
[/code]

An idea?

Thanks a lot!

Romain

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    fnRowCallback is no longer a property of oSettings - instead there is an array of callbacks so multiple callbacks can be defined as needed.

    This is how you would take account of the change: http://live.datatables.net/elonid/edit

    Allan
  • RomainRomain Posts: 2Questions: 0Answers: 0
    Thinks a lot!

    Issue fixed :)

    Romain
  • CHgsdCHgsd Posts: 25Questions: 0Answers: 0
    Mr. Allan,

    Thank you for fixing the code as well as the code cleanup. I diffed your version and my last version and was educated on a few things I had missed. I greatly appreciate your continued indulgence of this little plugin.

    Cheers,

    CHgsd
  • andi_sfandi_sf Posts: 7Questions: 0Answers: 0
    Allan's code works beautifully! Quick question: how would I have to change the code to highlight ALL instances of the Search word found - the code (http://live.datatables.net/elonid/edit) provided only highlights the first instance of the Search word found and then stops. Any hints would be greatly appreciated.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > Allan's code works beautifully!

    Say it again! I like hearing that ;-)

    It looks like that code does highlight all words that it matches at the moment. If I load up the example and type "Firefox" into the filter input, I get four rows in the table and "Firefox" has been lighted in each of them. Does that not happen for you?

    Allan
  • andi_sfandi_sf Posts: 7Questions: 0Answers: 0
    Hi Allan,

    well, compliments are in order for such a great piece of code ;)

    Yes, the current code highlights the search term in each row but in case a row has long text and let's say the search term would appear at least twice, then the current code would only highlight the first instance of the search term and then jumps out of the loop. Is there any quick change that would make it loop through ALL instances within the given longer text?

    Any hints are greatly appreciated!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi,

    I've just tried typing '1' into the filter and it does still appear to work as you are looking for. I've got a lot of rows with '1' appearing twice in it, "Firefox 1.0" and "1.7" for example.

    Allan
  • ravishravish Posts: 10Questions: 0Answers: 0
    Hi Allan Thanks For this Code .This thing is working fine but I have still problem in Fixed Column .Search is working fine but in Fixed Column it is not highlight column .Please guide
This discussion has been closed.