How to get the record count from Odata using DataJS.

Aug 18, 2011 at 11:26 AM

When we pass "$inlinecount=allpages" to the odata query it will return the records count as "<m:count>652</m:count>" in odata. My question is there any datajs function to get the record count similar like "" to get the values from odata.  or if we call like this"$inlinecount=allpages") how to get the record count using jquery template like we get the productID data from odata using this piece  of code "${$value.ProductID}".

Aug 18, 2011 at 2:44 PM

Hi anishjeyanth,

When you specify ?$inlinecount=allpages on a collection when reading with datajs, the resulting payload will contain the top level property "__count" (you can see more about this in our payload format documentation). So making a call like this:{ requestUri: "$inlinecount=allpages" }, function (data) { alert( data.__count ) });

would show that there are 9 entries in the Products collection. Note that this functionality is only available in OData v2.0 (if you are seeing <m:count>652</m:count> that means that service is v2). Does that answer your question? Please let me know if that's not what you were looking for.


Aug 18, 2011 at 4:10 PM

Hi BethMantey,

This is what i expected but instead of displaying the record count as an alert message i want it to display the record count in the jquery template, that i achieved by using ${$data.__count}. Our odata version is 2.0. using fiddler i saw the top level property "__count" but i don't know how to display the value. once again thanks for your great help, i appreciate your quick response and the detailed explanation.  DataJs is rocking and you guys are doing a wonderful job.


Aug 18, 2011 at 5:57 PM

Ah yes, something like this, modified from the Read Data sample:, function (data) {$("#searchResultsTemplate").tmpl(data).appendTo("#resultsArea");})

<div id="resultsArea"></div>
<script type="x-jquery-tmpl" id="searchResultsTemplate">
<div><span class='count'>${__count} results found</span></div>

I'm glad to help! Please let us know if you have any more questions.


Sep 12, 2011 at 9:15 AM

Hi BethMantey,

When displaying the datajs results we will  be displaying using the jquery template, is there a way to display the datajs results without using jquery template.   Also is it  true  that search engine wont index the url created by the jquery template and what we want to do for the url's to be indexed.


Sep 12, 2011 at 6:48 PM

Hi Anish,

You can avoid using jquery template by directly manipulating the DOM. You can find a tutorial on that here: For example you could populate a combobox with the Netflix genres by reading the url and adding the names from the result to the dropdown menu in the success function:

<select id='targetbox'></select>

<script type="text/javascript">
var element = document.getElementById("targetbox");

OData.defaultHttpClient.enableJsonpCallback = true;"", function (data) {
    for (var i = 0; i < data.results.length; i++) {
        var option = document.createElement("OPTION");
        option.text = data.results[i].Name;
        element.add(option, null);

I don't know much about getting a url indexed by a search engine but I haven't heard of jquery template affecting what gets indexed.


Sep 13, 2011 at 1:34 PM
Edited Sep 13, 2011 at 1:34 PM

Hi Beth,

This is what i am taking about.  Also regarding the search engine indexing the results displayed from the datajs either through the jquery template or by directly manipulating the DOM is not indexed by the search engine's if we open the page view  source the jquery and datajs codes only we can see not the results. thanks for the help keep up  your good work.. :-)