1

My current JavaScript implementation is based on answer in

How to get all items in a View using Client Object Model (JavaScript).

Is there a way to avoid loading the view first? Also, I am not interested in data (not event the Ids of items), just need the count.

Prakash
  • 666
  • 4
  • 19

2 Answers2

2

If environment is SP 2013 and it is needed to count total items in any view pages like AllItems.aspx, then the fastest way is following

ctx.ListData.Row.length

It will return totals items in this view.

Regarding this answer

It is the optimum way to get total items in a view I guess. Following is the process to get items from view

  • Need the CAML query from the view
  • Using this CAML query all items can be retrieved

So minimum request is mandatory.

If the CAML query of this view is already know to you, then you can retrieve all items by single request.

Atish Kumar Dipongkor
  • 13,371
  • 5
  • 32
  • 64
  • Thanks. I need this in an App targeted for SP Online. I have the name of list and one or more views of that list and need to get count of items in each of those views. – Prakash Dec 08 '15 at 07:58
  • 1
    Just remember to add context.load(view, "ViewQuery"); and context.load(items, "Include(ID)"); to the code from the answer. Then you have the count at items.get_data().length , still could take 4-5secs on a view with 5000 ish items – Anders Aune Dec 08 '15 at 09:49
  • @AndersAune, thanks for the tip, if you put it as a separate answer I will accept it. I guess that's the best optimization we can have for the scenario. – Prakash Dec 13 '15 at 18:56
-1

There's a couple of possibilities, looking at properties of the list rather than all the contents: http://sharepointpromag.com/sharepoint-development/using-splist-itemcount-vs-splist-items-count

Andrew
  • 1
  • 2
  • And also this is not answering the question.question is regarding a way in JSOM.not server obj mdoel –  Dec 08 '15 at 06:12