Skip to Content

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

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>
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Jan 24 at 10:34 AM

    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);
    }
    
    Add comment
    10|10000 characters needed 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.

  • Jan 24 at 12:48 PM

    Hi Former Member,

    thank you for your Answer.

    N. van Nieuwenhoven

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 24 at 12:48 PM

    Hi Former Member,

    thank you for your Answer.

    N. van Nieuwenhoven

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 24 at 12:48 PM

    Hi Former Member,

    thank you for your Answer.

    N. van Nieuwenhoven

    Add comment
    10|10000 characters needed characters exceeded