Handle a Table with JS

I wasn’t able to handle the Table widget from JS library.
The documentation says to use virtualWrite with many fields, but that is not supported by the JS library.
Any idea?

OK got it…I just need to send an array. A bit weird for an object-oriented language as JS but ok :slightly_smiling_face:
As a suggestion the library should define some methods specific for the table, as for the LCD and LED, to make it easier.
And write() should handle an object instead of an array.

Moreover there is a big confusion in the documentation between index, id and row id :frowning:
So an id is assigned to an entry and that id will be always linked to that entry even if moved. “Add” fix the id it seems.
Select, deselect, highlight and update work based on the id (while it’s written index, row index,…).
Order instead works with index, with base 0.
Someone should update the documentation or make it more clear, otherwise it’s a lot of trials and errors.

Sorry for the multiple self answer, but below the code to be added to the library for the table widget.

    this.WidgetTable = function(vPin) {
        this.pin = vPin;

        this.clear = function() {
                self.virtualWrite(this.pin, 'clr');

        this.add_row = function(id, name, value) {
                self.virtualWrite(this.pin, ['add', id, name, value]);

        this.update_row = function(id, name, value) {
            self.virtualWrite(this.pin, ['update', id, name, value]);

    this.highlight_row = function(id) {
	    self.virtualWrite(this.pin, ['pick', id]);

    this.select_row = function(id) {
	    self.virtualWrite(this.pin, ['select', id]);

    this.deselect_row = function(id) {
	    self.virtualWrite(this.pin, ['deselect', id]);

    this.move_row = function(old_row, new_row) {
	    self.virtualWrite(this.pin, ['order', old_row, new_row]);
1 Like