I have a query result named todos I am loading into a Handsontable in the 
view. The code below populates the Handsontable, but columns do not  appear 
in the order they are defined in db.define_table().
In this case, while the database columns are 
'id','title'.'description','priority', and 'completed', but Handsontable 
renders in the order 'description','title','completed', 'priority', and 
'id'.

What is the most idiomatic way to ensure Handsontable populates in the 
right column order? I know todos.colnames does list them as desired.

*CONTROLLER FILE default.py:*
# Fetch all todos completed or now into a query result
def index():
    return dict(todos=db(db.todo).select())


*VIEW FILE index.html:*
<!-- List all todos -->
{{extend 'layout_adminlte.html'}}
<script src="http://handsontable.com/dist/handsontable.full.js";></script>
<link rel="stylesheet" media="screen" 
href="http://handsontable.com/dist/handsontable.full.css";>
<div id="todo-table"></div>
<script>
var    
    todoTableData = {{=XML(todos.json())}},
    todoTableDiv = document.getElementById('todo-table'),
    todoTableSettings = {
        data:todoTableData
    },
    todoTableRef;    
todoTableRef = new Handsontable(todoTableDiv, todoTableSettings);
    
</script>

*MODEL FILE db.py:*
db.define_table('todo',
    Field('title',notnull=True),
    Field('description','text'),
    Field('priority','integer',default=3,
        requires=IS_IN_SET([1,2,3,4,5],
        labels=[T('Very low'), T('Low'), T('Medium'), T('High'), T('Very 
High')], zero=None)),
    Field('completed','boolean',default=False),format='%(name)s')

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to