List field and display few entries

49 views
Skip to first unread message

Mohammad

unread,
Aug 2, 2019, 3:09:57 AM8/2/19
to TiddlyWiki
  1. Assume you have a list of 14 entries
  2. The entries are given through a filter like [range[1, 14]]
  3. It is desired to display three entries all the time
  4. A next button shows the next three entries
    1. If pressing next button several times and you reached the end of list the last three entries are shown!
  5. A prev button shows the previous three entries
    1. If pressing prev button several times and you reached the beginning of list the first three entries are shown!
  6. So, always, any time three entries are visible on the  screen
Question
How to do this?

Partial solution, not works! 

\define test(filter:"[range[1,14]]")
<$vars filter=<<__filter__>> 
 last-item={{{ [list[stateTid]last[]] }}}
 first-item={{{ [list[stateTid]first[]] }}}
 stateTiddler="stateTid"
>

<$button>Prev List
<$action-setfield $tiddler="stateTid" list=""/>
<$action-listops $tiddler=<<stateTiddler>> $subfilter="[subfilter<filter>allbefore<first-item>last[3]] ~[subfilter<filter>first[3]]"/>
</$button>
<$button>Next List
<$action-setfield $tiddler="stateTid" list=""/>
<$action-listops $tiddler=<<stateTiddler>> $subfilter="[subfilter<filter>allafter<last-item>limit[3]] ~[subfilter<filter>last[3]]"/>
</$button>


</$vars>
\end

<<test>>

{{stateTid!!list}}




Any idea? AND if a simpler solution exist?

--Mohammad

Mohammad

unread,
Aug 2, 2019, 3:12:13 AM8/2/19
to TiddlyWiki
Note,
 As I did not know how to replace the list field using action-listops, I had to clear it and append to the empty list!

--Mohammad

Mohammad

unread,
Aug 2, 2019, 5:08:11 AM8/2/19
to TiddlyWiki
This is a solution to my question. It works but I think it is a little more complex than I expected and hopefully someone gives a simpler solution!
Complex TW code ate very difficult to maintain!


\define test(filter:"[range[1,14]]", stateTid:"testState")
<$vars filter=<<__filter__>> 
 last-item={{{ [list<__stateTid__>last[]] }}}
 first-item={{{ [list<__stateTid__>first[]] }}}
 stateTiddler=<<__stateTid__>>
>

<$button>Prev List
<$action-setfield $tiddler=<<stateTiddler>> list=""/>
<$list filter="[subfilter<filter>allbefore:include<first-item>last[4]count[]] -1 -2 -3 ~[[::false]]" variable=result>
   <$list filter="[<result>prefix[::false]]" variable=ignore>
        <$action-listops $tiddler=<<stateTiddler>> $subfilter="[subfilter<filter>first[4]]"/>
   </$list>
   <$list filter="[<result>!prefix[::false]]" variable=case>
        <$action-listops $tiddler=<<stateTiddler>> $subfilter="[subfilter<filter>allbefore:include<first-item>last[4]] ~[subfilter<filter>first[4]]"/>   
   </$list> 
</$list>
</$button>
<$button>Next List
<$action-setfield $tiddler=<<stateTiddler>> list=""/>
<$list filter="[subfilter<filter>allafter:include<last-item>first[4]count[]] -1 -2 -3 ~[[::false]]" variable=result>
   <$list filter="[<result>prefix[::false]]" variable=ignore>
        <$action-listops $tiddler=<<stateTiddler>> $subfilter="[subfilter<filter>last[4]]"/>
   </$list>
   <$list filter="[<result>!prefix[::false]]" variable=case>
        <$action-listops $tiddler=<<stateTiddler>> $subfilter="[subfilter<filter>allafter:include<last-item>first[4]] ~[subfilter<filter>last[4]]"/>  
   </$list> 
</$list>
</$button>


</$vars>
\end

<<test>>

{{testState!!list}}


In the above code four entries are visible all the time!

Added to Yazd!

--Mohammad

Mat

unread,
Aug 2, 2019, 6:47:49 AM8/2/19
to TiddlyWiki
Maybe Tobias version of the limit operator?

BTW, if you search for solutions on this, I think this functionality is used in so called "pagination" or "paging".

Also, I note that your last example actually gives "1 2 3 4" - "4 5 6 7" i.e the "4" is repeated.

<:-)

Mohammad

unread,
Aug 2, 2019, 6:55:10 AM8/2/19
to TiddlyWiki
Hi Mat,
 I will have a look on limit operator and see how it works!
That's right! I want to keep last item when show the next items and first one when show the previous item! I have added the include suffix.

<:-)
Reply all
Reply to author
Forward
0 new messages