In a javascript button I want to check weather a table contains any row.How to do that

  • 1
  • Question
  • Updated 3 years ago
Hi all I have a javascript button in a tab where i want to check that a table has any row or not .Note this table is in another tab and and different object(model).How can I do that ?
Photo of Raya Banerjee

Raya Banerjee

  • 456 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
If memory recalls,

var myTable = $('#my-table').data('object');
var tableList = myTable.list;
var renderedItems = tableList.renderedItems;
$.each(renderedItems, function (i, item) {
   console.log(i + ' - ' + item);
});


http://help.skuidify.com/m/11720/l/205336-skuid-ui-list
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Note: if the tab has not been rendered then the table may not be in the DOM.  You will need to look into this.  You can alway query the model, however.
Photo of Thimo

Thimo

  • 1,280 Points 1k badge 2x thumb
If you have a specific model on the other table you could do something like this:

var tableModel = skuid.$M("ModelForTable");
if(!!tableModel.data) {
    console.log('table contains row');
}