knockout.js - Improving CodeCamper with pagination -


i've been watching john papa's awesome video on pluralsight building spa.

now, i'm trying implement pagination sessions page , i'm not sure if i've done right way it. i'd appreciate feedback if has attempted similar.

here's i've done.

sessions.html


  <section>     <footer>         <ul class="pager">             <li>                 <button class="btn btn-info btn-small" data-bind="click: previous, enable:canprev"><i class="icon-angle-left"></i>previous</button>             </li>             <li>                 <button class="btn btn-info btn-small" data-bind="click: next, enable: canprev">next<i class="icon-angle-right"></i></button>              </li>         </ul>     </footer> </section> 

sessions.js


   var  currentpage = ko.observable(),      activate = function () {         currentpage(0);         return datacontext.getsessionpartials(sessions);    },     previous = function () {         currentpage(currentpage() - 1);         return datacontext.getsessionpartials(sessions, true, currentpage());     },      canprev = ko.computed(function () {         return currentpage() > 0;     }),      cannext = ko.computed(function () {         //return currentpage > 0;     }),      next = function () {         currentpage(currentpage() +1);         return datacontext.getsessionpartials(sessions, true, currentpage());     },     var vm = {         //existing stuff plus following:         previous: previous,         next: next,         currentpage: currentpage,         canprev: canprev,         cannext: cannext,     }; 

datacontext.js


 var query = entityquery.from('sessions')             .select('id, title, code, speakerid, trackid, timeslotid, roomid, level, tags')             .skip(currentpage * 5).take(5)                             .orderby('timeslotid, level, speaker.firstname')             .inlinecount(true); 

that works, except cannext, because don't know how add result of inlinecount sessions viewmodel. best way ?

with breeze can many rows want, breeze caches them in entity manager. show ones want on page. page size of 20, grab 40 if like, show 20. way have next 20 , know if there page. can simulate virtual paging way. ok, well, not elegant, works :)

another option prime call record count. recall vaguely breeze folks saying there might way total record count using breeze. i'll ask them chime in, can't remember concretely.

if using same call data count, set value entity in datacontext. or, return method wrapper object contains sessions , count. this...

// inside datacontext method's querysucceeded // data session data got // rowcount number of total rows.  return { sessions: data, rowcount: rowcount }; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -