-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mark.js in Tablesorter #1243
Comments
Hi @airthomas! I'll see what I can do! |
many thanks. |
I forgot about this because you closed it LOL... I basically copied the "official" mark.js demo code into the tablesorter playground. |
The demo looks great, any method to unmark thead ? and how can implement it if "filter by column". |
Ok, how about this demo It sets the marks per column using the filter widget, and the external input marks all columns. HTML Highlight: <input type="text" name="keyword" data-column="all">
<p>Options:</p>
<ul>
<li><input type="checkbox" name="opt[]" value="separateWordSearch" checked> separate word search</li>
<li><input type="checkbox" name="opt[]" value="diacritics" checked> diacritics</li>
<li><input type="checkbox" name="opt[]" value="debug"> debug</li>
</ul>
<button type="button" class="reset">Reset</button>
<table class="tablesorter">
<!-- ... -->
</table> Script $(function() {
var $table = $('table');
function mark() {
// Read the keyword
var keyword = $("input[name='keyword']").val();
// Determine selected options
var options = {};
$("input[name='opt[]']").each(function() {
options[$(this).val()] = $(this).is(":checked");
});
var $rows = $(".tablesorter tbody tr");
$rows.unmark();
var filters = $.tablesorter.getFilters($table);
$.each(filters, function(indx, filter) {
var col = indx === $table[0].config.columns ? '' : ':nth-child(' + (indx + 1) + ')';
$rows.children(col).mark(filter, options);
});
}
$("input[name='keyword']").on("input", mark);
$("input[type='checkbox']").on("change", mark);
$table
.on('filterEnd', mark)
.tablesorter({
theme: 'blue',
widgets: ['zebra', 'filter'],
widgetOptions: {
filter_external: 'input[name="keyword"]',
filter_reset: '.reset'
}
});
}); There is also some extra css to change the color of the mark per column: tr td:nth-child(1) mark {
background: #aa0000;
color: #fff;
}
tr td:nth-child(2) mark {
background: #00aa00;
color: #fff;
}
tr td:nth-child(3) mark {
background: #0000aa;
color: #fff;
} |
It's really cool and awesome !!! many thanks Mottie. |
bag and tag it, widget-mark.js ;) |
Actaully, I've been working on making a It should be ready for the next release. |
@Mottie Fantastic 🍻 |
Hello Mottie, In my case version 2.7.1 works beautifully 👍 as long as I enter uppercase text in filter_external field. I've got the impression that the Here is my TableSorter definition (sorry it's a bit crowded...):
I'm pretty sure I'm doing something wrong, only that I cannot figure out what. Tracing function What am I missing ? Thanks in advance for your help |
Hi @LaRemond! It looks like I actually left out the code to transfer the mark widgetOptions into the mark plugin. I've updated the widget in the master branch for now. |
Well done @Mottie, now it works really well. Thanks +++++ |
@Mottie Aren't you using unit tests in tablesorter? |
LOL, yes, but I've gotten lazy about making unit tests for all the widgets. |
Tip for newbies like myself working on oldish projects: jquery.mark.js and jquery.mark.min.js have UTF-8 as a character encoding.
If the charset is not specified and the default is not UTF-8, highlighting may just not work. As far as I can see, with a default charset other than UTF-8, strings used to match diacritics (such as "aÀÁÂÃÄÅàáâãäåĀāąĄ" , "cÇçćĆčČ", etc) are transformed into something completely unexpected, and therefore no match can be found. Hope it helps |
It might help if we encoded the strings as unicode. For example: "aÀÁÂÃÄÅàáâãäåĀāąĄ" becomes "a\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u0100\u0101\u0105\u0104" |
I wrote a hack to apply mark.js to tablesorter cells by parsing filter keywords and converting them to an array. This was before I learned that there was an official widget.
I tried the widget (8/1/2016 v2.27.2) and it works fine with inline data, but doesn't seem to highlight table data using paginated ajax requests. Keywords are highlighted in realtime, but when the ajax results are performed and the table is updated, there aren't any highlights. I'm using the default Mark settings from the Mark Widget Demo. Am I doing it wrong or is this a potential bug? I added this event listener and it forces a mark update after pager ajax updates. (I have a filter delay of 500ms, so the keywords are highlighted immediately, the ajax search is performed, data refresh occurs and then keywords are re-highlighted.)
|
I wanted to exclude some columns from being highlighted. There's no option to do this, but the effect can be somewhat nullified by using CSS overrides:
|
Thanks @JamoCA! The mark widget is set up to only update after a "filterEnd" event, which should be firing after a "pagerComplete". I'll check it out. I'll also look into add a column exception option in the mark widget. |
Ok @JamoCA! Try the updated widget in the master branch. Add a mark_tsIgnore: {
1 : true // second column (zero-based index)
} or add a "mark-ignore" class name to the header. |
Hi Mottie,
Sorry, it is a feature request, can mark.js or tablesorter self work word hgihlight in tablesorter after filter ?
Many thanks.
The text was updated successfully, but these errors were encountered: