Hi Andrew,
I got the point and it works. Thanks for your timely solution.
Afterthought: Since I need only to append an empty row to the table for the
user to enter data, java script solution avoided the round trip. I found
the that here
<http://viralpatel.net/blogs/dynamically-add-remove-rows-in-html-table-using-javascript/>.
Thank you once again.
On Saturday, September 6, 2014 12:51:00 PM UTC+5:30, trr wrote:
>
> I have a html table generated in controller. This table gets rendered. Now
> if the user wants more number of rows added to the table, I give a AddRows
> button. On the click of AddRows I would like to add rows to the existing
> table in the controller with empty cells and render it with the additional
> rows. How to achieve that? I have done this project in .NET. I am now
> migrating that to web2py. Pl. help. My code in controller is
> def generate_table_from_excel(num_rows):
>
> up = os.path.join(request.folder,'uploads')
> workbook = xlrd.open_workbook(os.path.join(request.folder,'uploads',
> 'meas.xls'))
> worksheet = workbook.sheet_by_name('Sheet1')
> num_rows = worksheet.nrows - 1
> num_cells = worksheet.ncols - 1
> curr_row = -1
> while curr_row < num_rows:
> d = {}
> curr_row += 1
> row = worksheet.row(curr_row)
> #print 'Row:', curr_row
> curr_cell = -1
> while curr_cell < num_cells:
> curr_cell += 1
> # Cell Types: 0=Empty, 1=Text, 2=Number, 3=Date, 4=Boolean,
> 5=Error, 6=Blank
> cell_type = worksheet.cell_type(curr_row, curr_cell)
> cell_value = worksheet.cell_value(curr_row, curr_cell)
> #print ' ', cell_type, ':', cell_value
> if curr_cell == 0:
> d['loc_of_work'] = cell_value
> if curr_cell == 1:
> d['n'] = cell_value
> if curr_cell == 2:
> d['t'] = cell_value
> if curr_cell == 3:
> d['l'] = cell_value
> if curr_cell == 4:
> d['b'] = cell_value
> if curr_cell == 5:
> d['d'] = cell_value
>
>
> i = 1
> form = FORM( TABLE(
> TR( TD('AgtNo:'), TD(session.agt_no) ),
> TR( TD('Jcod:'), TD(session.jcod) ),
> TR( TD('MeasDate:'),TD(session.meas_date) ),
> TR( TD('Shift:'), TD(session.shift) ),
> TR( TD( INPUT(_type='submit',_value='Save') ), TD(
> INPUT(_type='submit',_value='AddRows',_id='AddRows') ))
> ),
> INPUT(_id='txtNoOfRows',_type='hidden',_value=len(l)),
> TABLE(
> THEAD(TR(
> TH('Loc'),
> TH('n'),
> TH('t'),
> TH('l'),
> TH('b'),
> TH('d'),
> TH('Mat'),
> TH('UWt'),
> TH('Content'),
> TH('Remarks'),
> _style='halign:center' )),
>
> TBODY([TR(
> TD(TEXTAREA(_name='txt' + str(i+1) + '1',_id=
> 'txt'+str(i+1) +'1',value = r['loc_of_work'],_style=
> 'width:200px;height:50px;')),
> TD(INPUT(_name='txt' + str(i+1) + '2',_id=
> 'txt'+str(i+1) + '2',value=r['n'],_style='width:50px',_onblur=
> 'calculate_content()')),
> TD(INPUT(_name='txt' + str(i+1) + '3',_id=
> 'txt'+str(i+1) + '3' ,value=r['t'],_style='width:50px',_onblur=
> 'calculate_content()')),
> TD(INPUT(_name='txt' + str(i+1) + '4',_id=
> 'txt'+str(i+1) + <span style="col
> ...
--
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.