cancel
Showing results for 
Search instead for 
Did you mean: 

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

FRLEN
Participant

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>

Accepted Solutions (1)

Accepted Solutions (1)

former_member233511
Participant

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);
}
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.

Answers (3)

Answers (3)

FRLEN
Participant
0 Kudos

Hi xefimix,

thank you for your Answer.

nitinantoon

FRLEN
Participant
0 Kudos

Hi xefimix,

thank you for your Answer.

nitinantoon

FRLEN
Participant
0 Kudos

Hi xefimix,

thank you for your Answer.

nitinantoon