Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:04:55+00:00 2026-05-27T20:04:55+00:00

Im trying to loop a array with extjs xtemplate and create a table Ext.define(‘dataview_model’,

  • 0

Im trying to loop a array with extjs xtemplate and create a table

Ext.define('dataview_model', {
    extend    : 'Ext.data.Model',
    fields  : [
        {name: 'count',            type: 'string'},
        {name: 'maxcolumns',    type: 'string'},
        {name: 'maxrows',        type: 'string'},
        {name: 'numbers',        type: 'array'}
    ]
});

Ext.create('Ext.data.Store', {
    storeId : 'viewStore',
    model    : 'dataview_model',
    data    : [
        {count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']}
    ]
});

var tpl = new Ext.XTemplate(
    '<tpl for=".">',

        '<tpl if="count &gt; 0">',
            '<table class="view_table">',    
                '<tpl for="numbers">',    
                    '<tr>',
                        '<td>{.}</td>',
                    '</tr>',
                '</tpl>',    
            '</table>',
        '</tpl>',

    '</tpl>'
);

Ext.create('Ext.DataView', {
    width             : 500,
    height            : 200,
    renderTo          : Ext.getBody(),
    store             : Ext.getStore('viewStore'),
    tpl               : tpl    
});

this is the working example which i have so far

http://jsfiddle.net/6HgCd/

what i want to do is stop the loop once there is 5 rows and add other values to second column like below

+----+ +----+
|    | |    |
+----+ +----+
+----+ +----+
|    | |    |
+----+ +----+
+----+
|    |
+----+
+----+
|    |
+----+
+----+
|    |
+----+

any idea how to do this?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:04:56+00:00Added an answer on May 27, 2026 at 8:04 pm

    I can’t find a way to it with template only, but below is my solution which uses template and datachanged listener.

    Ext.create('Ext.data.Store', {
        storeId : 'viewStore',
        model    : 'dataview_model',
        data    : [
            {count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']},
            {count: '7', maxcolumns: '10', maxrows: '5', numbers: ['100','200','300','400','500','600','700']}
        ],
        listeners: {
            datachanged: function(store) {
                store.data.each(function(record) {
                    record.data.groupedNumbers = [];
                    for (var i = 0, j = 0; i < record.data.count; ++i, j = i % record.data.maxrows) {
                        record.data.groupedNumbers[j] = record.data.groupedNumbers[j] || { row: j, numbers: [] };
                        record.data.groupedNumbers[j].numbers.push(record.data.numbers[i]);
                    }
                });
            }
        }
    });
    
    var tpl = new Ext.XTemplate(
        '<tpl for=".">',
    
            '<tpl if="count &gt; 0">',
                '<table class="view_table" style="border: 1px solid black">',    
                    '<tpl for="groupedNumbers">',    
                        '<tr>',
                            '<tpl for="numbers">', 
                                '<td>{.}</td>',
                            '</tpl>',
                        '</tr>',
                    '</tpl>',    
                '</table>',
            '</tpl>',
    
        '</tpl>'
    );
    

    Working demo: http://jsfiddle.net/6HgCd/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to loop through an array fSel.sI, and based on the data inside,
I'm trying to loop through an array and copy across data, but after 1023
I am trying to loop through an array, and every 3 loops create a
I'm using smarty for my site, and I'm trying to loop through an array
I'm trying to use a foreach loop for an array of objects. Inside of
Trying to loop through my array of ImageViews, ran into the problem when it
I'm trying to loop through an array of strings using the foreach control, and
I am trying to loop through an array of usernames and for each username,
I'm getting the following error after shuffling an array, then trying to loop through
I am trying to loop over some values to insert data into a DB

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.