Calculate number of rows in a model

  • 3
  • Question
  • Updated 4 years ago
  • Answered
  • (Edited)
Hello again! I've a snippet which spits out a random selection of rows from a model but, to tidy it up, I need to know the total number of rows in a model (on the contact object).

I can't use a roll-up summary on the account as it doesn't work for the contact object so this needs to be done in javascript - is there a nice way of doing this using the API - or do I loop through the rows and count them?

Cheers!
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
  • mildly resplendent

Posted 4 years ago

  • 3
Photo of J.

J., Official Rep

  • 7,470 Points 5k badge 2x thumb
Louis,

We do have a way to get that count from the JS API. Each Skuid model contains an array named "data," which contains the rows within in the model. For instance, if your model is named "Contacts," you can get the number of rows as follows:
skuid.model.getModel('Contacts').data.length
Our skuid.model.Model api documentation contains the official write up. I hope that helps.
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
Perfect, thanks guys.
Photo of J.

J., Official Rep

  • 7,470 Points 5k badge 2x thumb
No problem! I'm glad we could help.