Ok, I think this is just a race condition, with the event listener typically being
registered after the livetable has been created and populated. Explicitly refreshing the
table with the following makes the rows display correctly:
var lt = window[lt_name];
var end = lt.limit;
var start = Math.max(lt.lastOffset, 1);
lt.clearCache();
lt.getRows(start, end, start, end);
So instead, here's another question for LiveTable gurus: Is there a way to prevent a
livetable from updating? I'd like to place the LiveTable in a div that is initially
hidden, and I only want it to be active when the div is made visible.
Thanks,
Bryn
-----Original Message-----
From: Bryn Jeffries
Sent: Saturday, 29 August 2015 6:28 AM
To: XWiki Users
Subject: Livetable events
I've been following the instructions in
http://platform.xwiki.org/xwiki/bin/view/DevGuide/LiveTable to modify the
contents of a livetable, with the following jQuery:
require(['jquery', 'xwiki-events-bridge'], function($) {
document.observe("xwiki:livetable:newrow", function(ev) {
$('.working').each(function () {
var txt = $(this).text();
if (txt== "true") {
$(this).append($("<span>", {
class: "glyphicon glyphicon-ok"
}))
} else if (txt == "false") {
$(this).append($("<span>", {
class: "glyphicon glyphicon-remove"
}))
}
});
document.fire("xwiki:livetable:ready", {});
});
});
However, this only appears to work once I cause the livetable to update after
it has loaded the first time (e.g. by sorting a column). How do I get it to run
the first time?
Also, what is the purpose of the last line?:
document.fire("xwiki:livetable:ready", {}); This appears in the example code
"Display ratings in the Livetable on row event", but doesn't obviously
affect
anything if I remove it.