Note that there are some explanatory texts on larger screens.

plurals
  1. POPagination issues with knockout js
    primarykey
    data
    text
    <p>I have the following html binding in knockout</p> <pre><code>&lt;div data-bind="with: talkData"&gt; &lt;div data-bind="foreach: Talks"&gt; &lt;p data-bind="text: Title"&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt; &lt;button class="btn btn-success previous" data-bind="click: $root.PageBack, disable: $root.page() == 1"&gt;Prev&lt;/button&gt; &lt;button class="btn btn-success next" data-bind="click: $root.PageNext, disable: $root.page() == $root.talkData().TotalPageCount"&gt;Next&lt;/button&gt; &lt;/p&gt; </code></pre> <p>With the following model:</p> <pre><code>$(function() { function TalksViewModel() { var self = this; self.page = ko.observable(1); self.records = ko.observable(1); self.totalPages = ko.observable(1); self.talkData = ko.observable(); self.IsPrevEnabled = isPrevEnabled; function pageBack(item) { self.page(self.page() - 1); loadDataFromServer(); } self.PageBack = pageBack; function pageNext(item) { console.log("page next"); self.page(self.page() + 1); loadDataFromServer(); } self.PageNext = pageNext; function loadDataFromServer() { var url = '/Talks/GetPagedTalks'; self.talkData(null); $.get(url, { page: self.page() }, self.talkData); } // Initial page loadDataFromServer(); } ko.applyBindings(new TalksViewModel()); }); </code></pre> <p>The JSON returned from the 'GetPagedTalks' call is:</p> <pre><code>Talks: [{Title:Philippians 1:12-26,…}, {Title:Philippians 1:1-11,…}, {Title:Devoted Lives: ,…}] 0: {Title:Philippians 1:12-26,…} 1: {Title:Philippians 1:1-11,…} 2: {Title:Devoted Lives: ,…} TotalPageCount: 59 TotalRowCount: 177 </code></pre> <p>The next and previous buttons work but I'm really struggling to know how to set the total number of pages from the data returned from the GET call.</p> <p>The line: disable: $root.page() == $root.talkData().TotalPageCount</p> <p>Isn't working at all. I assumed TotalPageCount would be part of talkData.</p> <p>Any help appreciated.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload