Highlighting search and stateSave: true

Highlighting search and stateSave: true

brainformatikbrainformatik Posts: 6Questions: 0Answers: 0

Hi everybody,

I have a problem with hightlighting search results and stateSave = true.

I've used a solution of this thread http://datatables.net/forums/discussion/2123/filter-post-processing-and-highlighting/p2

To show you the problem I've created a small example http://jsfiddle.net/tc1ryoah/1/ (tested with Chrome and FF with Firebug).

Please try to search something (result is highlighted) and run the example again -> no highlighting.

If you then perform any further action like sorting or page navigation, highlighting works again.

Any ideas where the problem could be (callback not triggered, order of initialisation ...)?

Replies

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    The thread you linked to is from 2012 which is long before the introduction of the search highlighting plug-in.

    You might be interested in this pull request which addresses the issue you are seeing. I need to merge that change in.

    Allan

  • brainformatikbrainformatik Posts: 6Questions: 0Answers: 0

    Hi allan,

    thank you for your quick answer, I haven't seen yet, that there is a separate plugin for this.

    I will try this and also the pull request you've mentioned.

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    I've just updated the search highlighting plug-in for DataTables to add support for state saving and initial filters. The latest version of the file is available in git and will be released to the DataTables CDN in the next few weeks.

    Allan

  • brainformatikbrainformatik Posts: 6Questions: 0Answers: 0

    Highlighting after refreshing the page works now.

    Another action after that highlighting doesn't work is ColReorder.

  • brainformatikbrainformatik Posts: 6Questions: 0Answers: 0

    I've added following code to highlight plugin now which works for me at the moment.

    If somebody has other ideas, please let me know.

    $(document).on('column-reorder', function(e, settings) {
    
        var table = new $.fn.dataTable.Api( settings );
        var body = $( table.table().body() );
    
        if (
            $( table.table().node() ).hasClass( 'searchHighlight' ) || // table has class
            settings.oInit.searchHighlight                          || // option specified
            $.fn.dataTable.defaults.searchHighlight                    // default set
        ) {
            // initial highlight for state saved conditions and initial states
            if ( table.search() ) {
                highlight( body, table );
            }
        }
    });
    
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    I would suggest a much more simple change, which is just to listen for the column-reorder event on the DataTable in question. I've committed that here.

    Thanks,
    Allan

  • brainformatikbrainformatik Posts: 6Questions: 0Answers: 0
    edited January 2015

    Thank you, works perfectly.

    Do I need full forum access to accept an answer?

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    No - the post was opened as a discussion rather than a question, so there are no "Answers" as such. But that's fine - we'll just leave it like this :-)

    Allan

This discussion has been closed.