Hi all
First a bit of background. The VT (Virtual Tables) were
quite under the radar since used only sparingly. On Demo,
the VT is used to send Email to Customers. Which does
not really show the full VT potential.
IMO, the VT can be used as DB Views.
Let's say the DB view is only for SELECT SQL.
Hence, we can build the Server Module with any SQL we need, and pass that to VT
Client Module to show the table.
However, this JS is where the performance issue is.
to get the nice formatting, since Jam Ace is not great for c/p.
Consider this code which gets the data from Server Module:
function on_after_open(item) {
item.alert('Working!');
item.server('get_records', function(records) {
records.forEach(function(rec) {
item.append();
item.id.value = rec.product_id;
item.product_name.value = rec.product_name;
item.target_level.value = rec.target_level;
item.quantity_on_hold.value = rec.quantity_on_hold;
item.quantity_on_order.value = rec.quantity_on_order;
item.quantity_on_back_order.value = rec.quantity_on_back_order;
item.quantity_on_hand.value = rec.quantity_on_hand;
item.quantity_purchased.value = rec.quantity_purchased;
item.quantity_sold.value = rec.quantity_sold;
item.post();
});
});
}
Looks ok, right?
Wrong. The performance is just not there, it is super slow.
One would opt for DataTables.js (DT), to get the performance up. But that
just complicates stuff, it is completely different technology, even tho it really
works fabulously with Jam.
Now consider this code, provided by Master Yoda himself (AY):
function on_after_open(item) {
item.alert('Working!');
item.server('get_records', function(records) {
item.disable_controls();
try {
records.forEach(function(rec) {
item.append();
item.id.value = rec.product_id;
item.product_name.value = rec.product_name;
item.target_level.value = rec.target_level;
item.quantity_on_hold.value = rec.quantity_on_hold;
item.quantity_on_order.value = rec.quantity_on_order;
item.quantity_on_back_order.value = rec.quantity_on_back_order;
item.quantity_on_hand.value = rec.quantity_on_hand;
item.quantity_purchased.value = rec.quantity_purchased;
item.quantity_sold.value = rec.quantity_sold;
item.post();
});
item.first();
}
finally {
item.enable_controls();
}
});
}
And that, my friends, is the Holly Grail of VT. Instant performance boost!
So lets see what the Master Yoda says about it:
The idea behind these changes is that the controls (DOM elements that display the data) in Jam.py are data-aware.
Every time a record is added, deleted or modified these changes are reflected by controls.
It makes the filling of a table by adding records ineffective, every change of every field and so on must be updated.
So in the code above I turned off this data-awareness by the disable_controls method and after records are added
turned it on with enable_controls.
The tables in Jam.py use virtual scrolling and display only data that is visible and are very fast.
I also executed the first method to move to the first record.
I created a small example with two tables, one VT and one DT, showing the same select SQL:
Replace the code in question for VT and see the performance boost.
It is really fast.
Enjoy
D.