3

I'm fairly new to Javascript trying to access some data from a table I've created using footable. It should be simple but I can't seem to get it to work.

So far I can drill down to the table's rows using table.rows, which is returns a class. Within that class is an 'all' array which I'm trying to access. In the example, I'm following table_variable.rows.all works, but for me, the result returned is 'undefined'.

What is the correct way to access this array from the class? I've tried other ways such as: table_variable.rows['all'] but none seem to have worked.

Many thanks

EDIT - more code:

I'm creating the table here and later passing the variable to the totals function:

ft = FooTable.init('#showcase-example-1')

function totals(ft)
         {
            console.log(ft); 
            console.log(ft.rows);
            console.log(ft.rows.all);
         }

The error is on the ft.rows.all line saying 'undefined'.

blountdj
  • 599
  • 1
  • 11
  • 23
  • 1
    Can you post the code where you're seeing this issue? There isn't much to go on here without more context. – CRice Mar 23 '18 at 16:40
  • Is that a typo in your question, or did you switch from `rows` to `row` in your code like that? – kshetline Mar 23 '18 at 16:43
  • @CRice : added more code, does that help at all? – blountdj Mar 23 '18 at 16:48
  • @kshetline : sorry yes typo, now edited – blountdj Mar 23 '18 at 16:49
  • @blountdj may you check, in your totals function, if doing: `console.log(JSON.parse(JSON.stringify(ft.rows)));` is logging an object with `all` defined? It may happen that `rows.all` is being defined / compiled **after** your function has executed. Also, the exact error may be helpful. – briosheje Mar 23 '18 at 16:58
  • @briosheje I've run that and all is defined there, however the array is empty. If I look into the the log for all.rows there are 25 objects in the all array so the all is there – blountdj Mar 23 '18 at 17:03
  • If you can confirm that the above line logs an object where the `all` property is an empty array, it means that the data is injected **later**. However, it still shouldn't throw an exception, since an empty array is not undefined. Are you 100% sure that the error is thrown at that line specifically? (ft.rows.all) – briosheje Mar 23 '18 at 17:06
  • @blountdj is it possible to load your code in jsbin or jsfiddle so we see what's going on? if not, can you load 'table.rows' output to your question? or at least screenshot of what the result of that output is – iceveda06 Mar 23 '18 at 17:06
  • 1
    Oh, nevermind, in the **official documentation** it is said that .all is `protected`: https://fooplugins.github.io/FooTable/docs/jsdocs/FooTable.Rows.html . You should use, instead, the init rows event to access the rows: https://fooplugins.github.io/FooTable/docs/jsdocs/FooTable.html#.event:Rows%init.ft.rows%2522 – briosheje Mar 23 '18 at 17:10
  • @iveveda06 I have an image here https://pasteboard.co/Hdg1tr6.png. This is the output for console.log(ft.rows); – blountdj Mar 23 '18 at 17:12
  • @briosheje thanks, that why it doesn't work then. Just not sure how to implement the other method – blountdj Mar 23 '18 at 17:20
  • 1
    @blountdj : I think it's as simple as `.on('init.ft.rows', function(e, instance, rows){ });` or something like that. Just look for an example of any event of the FooTable really, then bind `init.ft.rows` and you're done – briosheje Mar 24 '18 at 10:35

0 Answers0