Skip to Content
1

Max 5 results in the table with a next and previous function

Jan 24 at 09:44 AM

43

avatar image

Dear GuruDevelopers,

I'm currently making a questionary app in webide and I want that every page to have 5 questions. How do we build this in with a randomiser who randomly selects the quesitons and make sure that when we press for the next page or previeus that the questions don't change or questions occur several times over different pages?

This is what I have so far.

<Table  id="__table0" inset="false" items="{path: '/Questions'}" visibleRowCount="5">
    <items>
        <ColumnListItem id="__item0">
            <cells>
      <Text select="_GroupQuestions"  key="{/QID}" text="{Qn}" id="__text3"/>
            </cells>
            <cells style="text-align:end"> 
                <RatingIndicator iconSize="32px" maxValue="5"/>
            </cells>
        </ColumnListItem></items>
    <columns>
        <Column id="__column2" width="80%">
    <header>
    </header>
</Column>
<Column id="__column3" class="tblstarend">
    <header>
    </header>
</Column>
		</columns></Table>
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Efim Parshin Jan 24 at 10:34 AM
1

Hi! So if we basically have Array of questions, we can randomly split into additional model property.
Something like this:

var items = [{Qn: 'q1'}, {Qn: 'q2'} ...];<br>var aPages = [];

//randomly split pages<br>while (items.length > 0) {
	var lastPage = aPages[aPages.length - 1];
	if(!lastPage || lastPage.length === 5) {
		lastPage = aPages[aPages.push([]) - 1];
        }
	
    lastPage.push(items.splice(Math.floor(Math.random()*items.length), 1)[0])
}

//set new prop for model
this.myModel.setProperty('/QPages', aPages);
this.currentPageId = 0

//setup initial page<br>this.byId('__table0').bindObject('/QPages/' + this.currentPage);

//////////////////////////////////////////////////////////////////////
//change view binding of table: items="{}"

//And change pages with switching binding context of table:
onNextPagePress: function() {
  this.byId('__table0').bindObject('/QPages/' + ++this.currentPage);
}

onPrevPagePress: function() {
   this.byId('__table0').bindObject('/QPages/' + --this.currentPage);
}
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi, Let me explain the situation:

We have a HANAXS database with approximately 200 questions. What we want is 5 pages with 5 questions each. These questions should be selected at random but a question may not occur twice in the 5 pages. Our current situation is that it retrieves all of the questions (limited to the standard 100) by binding it to the table.

I hope this clarifies the situation.

1
N. van Nieuwenhoven Jan 24 at 12:48 PM
0

Hi Former Member,

thank you for your Answer.

N. van Nieuwenhoven

Share
10 |10000 characters needed characters left characters exceeded
N. van Nieuwenhoven Jan 24 at 12:48 PM
0

Hi Former Member,

thank you for your Answer.

N. van Nieuwenhoven

Share
10 |10000 characters needed characters left characters exceeded
N. van Nieuwenhoven Jan 24 at 12:48 PM
0

Hi Former Member,

thank you for your Answer.

N. van Nieuwenhoven

Share
10 |10000 characters needed characters left characters exceeded