Dear All, I recently used a SQLFORM.grid in my app and I wanted #1 the possibility to have checkboxes to select multiple row to delete #2 customize the text of the submit button #3 have a "select all" checkbox in the table header.
#1 was easy to solve with the help of this mailing list. (see https://groups.google.com/d/msg/web2py/lbNf_UoId7s/XvDFLYHQpIsJ) For #2 and #3 I modified web2py itself (sqlhtml.py - see diff below) - and added a few lines of javascript. Questions : 1. what is the easiest way to active my goal ? 2. is this code contribution worth adding into the trunk ? Thanks Seb *********** marsu:gluon sst$ diff -c sqlhtml.py.ORIG sqlhtml.py *** sqlhtml.py.ORIG Wed Mar 28 22:42:03 2012 --- sqlhtml.py Wed Mar 28 22:42:45 2012 *************** *** 1400,1405 **** --- 1400,1406 ---- editable=True, details=True, selectable=None, + selectable_text=None, create=True, csv=True, links=None, *************** *** 1702,1708 **** head = TR(_class=ui.get('header','')) if selectable: ! head.append(TH(_class=ui.get('default',''))) for field in fields: if columns and not str(field) in columns: continue if not field.readable: continue --- 1703,1709 ---- head = TR(_class=ui.get('header','')) if selectable: ! head.append(TH(INPUT(_type='checkbox', _name='selectAll', _id='selectAll', value='off'), _class=ui.get('default',''))) for field in fields: if columns and not str(field) in columns: continue if not field.readable: continue *************** *** 1852,1858 **** htmltable.append(tbody) htmltable = DIV(htmltable,_style='width:100%;overflow-x:auto') if selectable: ! htmltable = FORM(htmltable,INPUT(_type="submit")) if htmltable.process(formname=formname).accepted:# htmltable.vars.records = htmltable.vars.records or [] htmltable.vars.records = htmltable.vars.records if type(htmltable.vars.records) == list else [htmltable.vars.records] --- 1853,1861 ---- htmltable.append(tbody) htmltable = DIV(htmltable,_style='width:100%;overflow-x:auto') if selectable: ! htmltable = FORM(htmltable,INPUT(_type="submit", _value=selectable_text if selectable_text else T('Submit'))) ! htmltable.element(_id='selectAll')['_onClick']="toggleAll(this, 'records');" if htmltable.process(formname=formname).accepted:# htmltable.vars.records = htmltable.vars.records or [] htmltable.vars.records = htmltable.vars.records if type(htmltable.vars.records) == list else [htmltable.vars.records] ********** //in the view <script type="text/javascript"> function toggleAll(source,name) { checkboxes = document.getElementsByName(name); for(var i in checkboxes) checkboxes[i].checked = source.checked; } </script>