[web2py] Re: Trying to use the LOAD helper, if a button is clicked
Looks like the new datatables.net v1.10 has a new API so there are now probably better ways to do this than I showed. On Monday, June 23, 2014 4:51:53 AM UTC-5, Tomeu Roig wrote: > > Thanks Brian > > El lunes, 23 de junio de 2014 03:56:32 UTC+2, Brian M escribió: >> >> Tomeu, >> >> At the moment I'm just letting datatables.net enhance a plain html table >> for me. One of these days I'll probably get around to giving it a json >> datasource but so far it hasn't been a priority for my usage. >> >> As a bonus, here's some of how to update the datatables.net display >> after using the edit dialog. (So just the edited record's row in the >> datatable gets updated rather than a full page refresh) >> >> In controller >> #after you'd done the necessary DB updates... >> >> #tell browser to close the jqueryui dialog >> response.js =XML( '$("#edit_dialog").dialog("close");') >> >> #prepare for display update >> edit_icon = IMG(_src=URL(c="static",f="images/page_white_edit.png"), _alt >> ="Click to edit") >> >> #prep javascript code for datatables.net to update the existing row's >> display >> #basically just a json list of td values >> row_update = simplejson.dumps([updated_record.table.first_name, >> updated_record.table.last_name, updated_record.table2.name, >> str(A(edit_icon, _href=URL(r=request,f='edit_loader', args=[ >> updated_record.table.record_id, mode]), _class="updateDialog")), >> updated_record.table.email, updated_record.table.someother_id]) >> >> #using the tr#id method to update table is unreliable (the TR won't have >> an id if it was added dynamically >> #instead use the row index provided by datatables.net itself (we passed >> it in via ajax vars) >> #essentially fnUpdate(new td values, which row) >> response.js += '$("#your_table_selector").dataTable().fnUpdate( '+ >> row_update+', '+request.vars['datatable_row_index']+',0, false );' >> >> #also using jGrowl to give an acknowledgement >> message = T("%s updated") % (updated_record.table.first_name) >> response.js += '$.jGrowl("'+message+'");' >> >> >> And as the second bonus, how to insert a brand new row in the datatable. >> (Below my datatable.net is another always visible LOAD()ed form for >> creating a new record. Upon submission the new record is inserted into the >> existing datatable via javascript returned in web2py's response) >> >> In controller: >> #do the database insert then >> #prepare for display update >> edit_icon = IMG(_src=URL(c="static",f="images/page_white_edit.png"), _alt >> ="Click to edit") >> >> table_update = simplejson.dumps([new_record.table.first_name, new_record. >> table.last_name, >> new_record.table2.name, str(A(edit_icon, _href=URL(r=request,f= >> 'edit_loader', >> args=[new_record.table.record_id, form.vars.mode]), _class= >> "updateDialog")), >> new_record.table.email, new_record.table.foreign_id]) >> >> #issue command for adding new row to datatable >> response.js = 'vol_table.fnAddData('+table_update+');' >> >> Good luck >> >> ~Brian >> >> >> On Sunday, June 22, 2014 4:44:33 PM UTC-5, Tomeu Roig wrote: >>> >>> Thanks Brian, nice think to get a full href for pass to the >>> $web2py.component. >>> >>> I see that you use datatables.net. Do you use some plugin o directly >>> you pass json from controller? >>> >>> I want use in a new project but i have doubts have to implement. Can you >>> give me some idea? >>> >>> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
Thanks Brian El lunes, 23 de junio de 2014 03:56:32 UTC+2, Brian M escribió: > > Tomeu, > > At the moment I'm just letting datatables.net enhance a plain html table > for me. One of these days I'll probably get around to giving it a json > datasource but so far it hasn't been a priority for my usage. > > As a bonus, here's some of how to update the datatables.net display after > using the edit dialog. (So just the edited record's row in the datatable > gets updated rather than a full page refresh) > > In controller > #after you'd done the necessary DB updates... > > #tell browser to close the jqueryui dialog > response.js =XML( '$("#edit_dialog").dialog("close");') > > #prepare for display update > edit_icon = IMG(_src=URL(c="static",f="images/page_white_edit.png"), > _alt="Click > to edit") > > #prep javascript code for datatables.net to update the existing row's > display > #basically just a json list of td values > row_update = simplejson.dumps([updated_record.table.first_name, > updated_record.table.last_name, updated_record.table2.name, > str(A(edit_icon, _href=URL(r=request,f='edit_loader', args=[ > updated_record.table.record_id, mode]), _class="updateDialog")), > updated_record.table.email, updated_record.table.someother_id]) > > #using the tr#id method to update table is unreliable (the TR won't have > an id if it was added dynamically > #instead use the row index provided by datatables.net itself (we passed > it in via ajax vars) > #essentially fnUpdate(new td values, which row) > response.js += '$("#your_table_selector").dataTable().fnUpdate( '+ > row_update+', '+request.vars['datatable_row_index']+',0, false );' > > #also using jGrowl to give an acknowledgement > message = T("%s updated") % (updated_record.table.first_name) > response.js += '$.jGrowl("'+message+'");' > > > And as the second bonus, how to insert a brand new row in the datatable. > (Below my datatable.net is another always visible LOAD()ed form for > creating a new record. Upon submission the new record is inserted into the > existing datatable via javascript returned in web2py's response) > > In controller: > #do the database insert then > #prepare for display update > edit_icon = IMG(_src=URL(c="static",f="images/page_white_edit.png"), > _alt="Click > to edit") > > table_update = simplejson.dumps([new_record.table.first_name, new_record. > table.last_name, > new_record.table2.name, str(A(edit_icon, _href=URL(r=request,f= > 'edit_loader', > args=[new_record.table.record_id, form.vars.mode]), _class= > "updateDialog")), > new_record.table.email, new_record.table.foreign_id]) > > #issue command for adding new row to datatable > response.js = 'vol_table.fnAddData('+table_update+');' > > Good luck > > ~Brian > > > On Sunday, June 22, 2014 4:44:33 PM UTC-5, Tomeu Roig wrote: >> >> Thanks Brian, nice think to get a full href for pass to the >> $web2py.component. >> >> I see that you use datatables.net. Do you use some plugin o directly you >> pass json from controller? >> >> I want use in a new project but i have doubts have to implement. Can you >> give me some idea? >> >> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
Tomeu, At the moment I'm just letting datatables.net enhance a plain html table for me. One of these days I'll probably get around to giving it a json datasource but so far it hasn't been a priority for my usage. As a bonus, here's some of how to update the datatables.net display after using the edit dialog. (So just the edited record's row in the datatable gets updated rather than a full page refresh) In controller #after you'd done the necessary DB updates... #tell browser to close the jqueryui dialog response.js =XML( '$("#edit_dialog").dialog("close");') #prepare for display update edit_icon = IMG(_src=URL(c="static",f="images/page_white_edit.png"), _alt="Click to edit") #prep javascript code for datatables.net to update the existing row's display #basically just a json list of td values row_update = simplejson.dumps([updated_record.table.first_name, updated_record.table.last_name, updated_record.table2.name, str(A(edit_icon, _href=URL(r=request,f='edit_loader', args=[ updated_record.table.record_id, mode]), _class="updateDialog")), updated_record.table.email, updated_record.table.someother_id]) #using the tr#id method to update table is unreliable (the TR won't have an id if it was added dynamically #instead use the row index provided by datatables.net itself (we passed it in via ajax vars) #essentially fnUpdate(new td values, which row) response.js += '$("#your_table_selector").dataTable().fnUpdate( '+row_update +', '+request.vars['datatable_row_index']+',0, false );' #also using jGrowl to give an acknowledgement message = T("%s updated") % (updated_record.table.first_name) response.js += '$.jGrowl("'+message+'");' And as the second bonus, how to insert a brand new row in the datatable. (Below my datatable.net is another always visible LOAD()ed form for creating a new record. Upon submission the new record is inserted into the existing datatable via javascript returned in web2py's response) In controller: #do the database insert then #prepare for display update edit_icon = IMG(_src=URL(c="static",f="images/page_white_edit.png"), _alt="Click to edit") table_update = simplejson.dumps([new_record.table.first_name, new_record. table.last_name, new_record.table2.name, str(A(edit_icon, _href=URL(r=request,f= 'edit_loader', args=[new_record.table.record_id, form.vars.mode]), _class= "updateDialog")), new_record.table.email, new_record.table.foreign_id]) #issue command for adding new row to datatable response.js = 'vol_table.fnAddData('+table_update+');' Good luck ~Brian On Sunday, June 22, 2014 4:44:33 PM UTC-5, Tomeu Roig wrote: > > Thanks Brian, nice think to get a full href for pass to the > $web2py.component. > > I see that you use datatables.net. Do you use some plugin o directly you > pass json from controller? > > I want use in a new project but i have doubts have to implement. Can you > give me some idea? > > -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
Thanks Brian, nice think to get a full href for pass to the $web2py.component. I see that you use datatables.net. Do you use some plugin o directly you pass json from controller? I want use in a new project but i have doubts have to implement. Can you give me some idea? -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
Thanks. -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
> > trying to find out more about $.web2py.component, but it's not in the > book. Chapter 11 mentions web2py_ajax_component but it isn't mentioned > in Chapter 12 as indicated. It used to be web2py_component (actually, you can still use that), but now it's $.web2py.component. Anthony, I don't understand "If you want to dynamically add a component in > the browser, you cannot use the LOAD helper" as the example also > includes a {{= }}. Then again, I don't really understand javascript > either. The example includes the URL of the component, which is fixed, not dynamic. > When to use LOAD or $.web2py.component ? > LOAD will result in the component loading as soon as the parent page loads. If you instead need a component to appear at some later time as a result of some user action, then you have to call $.web2py.component directly. Anthony -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
Thank you Anthony! This works :) Thank you too Carlos On Monday, June 16, 2014 4:33:05 PM UTC+3, Anthony wrote: > > If you want to dynamically add a component in the browser, you cannot use > the LOAD helper, which is a Python helper that is serialized on the server. > Instead, use the $.web2py.component() Javascript function. Something like: > > > > > > Anthony > > On Friday, June 13, 2014 7:47:34 PM UTC-4, Omri Levy wrote: >> >> Hi , >> >> So I have a ticket system, and I want to allow user to edit the ticket >> without leaving the page. >> I don't want to LOAD the edit_page and hide it, but only load it once >> user is clicking on the ticket body. >> Another thing is, when user edits the ticket, he should again see changes >> on the same page. >> >> Is this possible? I'm a bit confused, because LOAD works fine, but not >> when using conditions with JS. >> >> Thanks. >> > -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
Hi, trying to find out more about $.web2py.component, but it's not in the book. Chapter 11 mentions web2py_ajax_component but it isn't mentioned in Chapter 12 as indicated. An old reference perhaps. Anthony, I don't understand "If you want to dynamically add a component in the browser, you cannot use the LOAD helper" as the example also includes a {{= }}. Then again, I don't really understand javascript either. When to use LOAD or $.web2py.component ? Thanks On Thursday, June 19, 2014 1:25:48 PM UTC+10, Brian M wrote: > > Here's how I'm doing it in an app. I'm not using grid or smartgrid but > rather a datatables.net table where each row has a linked edit button. > There may be other (better?) ways to do it but this works for me. > > Each record includes: > {{=A(edit_icon, _href=URL(r=request,f='edit_item', args=[record_id]), > _class="updateDialog")}} > > > And then I've got javascript to intercept the clicks on the edit icon, > figure out which record's edit page it links to and instead load that edit > form within a jqueryui dialog. > > //Manage the display of the dialog for editing details. > $(function() { > $("#edit_dialog").dialog({ > width: 600, > height: 355, > modal: true, > //hide: 'slide', > autoOpen: false > }); > //opens the dialog whenever one of the edit icons is clicked > $(document).on('click', 'a.updateDialog', function() { > //get url to load from the clicked link's href > var url = $(this).attr('href'); > > //get the datatable row ID that we're editing > var nTr = $(this).closest("tr").get(0); // key line that gets the > closest TR > aPos = vol_table.fnGetPosition( nTr ); // gets the position > within the datatable > > //augment the url with the row index (aPos) because need to be > able refer to it in the server response to be able to update correct row's > display > url = url+'/'+aPos; > > //load up the actual form from server & embed it within the > dialog's body element (edit_form_loader) > $.web2py.component(url, 'edit_form_loader');//request web2py's > ajax to reload the component with the URL for this specific item's info > > $('#edit_dialog').dialog('open');//show the dialog > return false; > }); > }); > > > > > > > Good Luck! > ~Brian > > On Wednesday, June 18, 2014 9:45:08 AM UTC-5, Tomeu Roig wrote: >> >> I call a function that content a grid or smartgrid and need pass args and >> (user_signature=True), how i can make it? >> >> now I use in controller response.js like: >> >> tab_history = """jQuery('#historial >> a[href="#historico"]').click(function(){ >> $.web2py.component("%s", target="historico"); >> })""" % URL('albaranes', 'view_albs_cli.load', >> args=[cliente_id,'historico'],user_signature=True) >> response.js = tab_history >> >> It's works but i would like make the same in the view, it's possible? >> >> thanks. >> >> El lunes, 16 de junio de 2014 15:33:05 UTC+2, Anthony escribió: >>> >>> If you want to dynamically add a component in the browser, you cannot >>> use the LOAD helper, which is a Python helper that is serialized on the >>> server. Instead, use the $.web2py.component() Javascript function. >>> Something like: >>> >>> >>> >>> >>> >>> Anthony >>> >>> On Friday, June 13, 2014 7:47:34 PM UTC-4, Omri Levy wrote: Hi , So I have a ticket system, and I want to allow user to edit the ticket without leaving the page. I don't want to LOAD the edit_page and hide it, but only load it once user is clicking on the ticket body. Another thing is, when user edits the ticket, he should again see changes on the same page. Is this possible? I'm a bit confused, because LOAD works fine, but not when using conditions with JS. Thanks. >>> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
Here's how I'm doing it in an app. I'm not using grid or smartgrid but rather a datatables.net table where each row has a linked edit button. There may be other (better?) ways to do it but this works for me. Each record includes: {{=A(edit_icon, _href=URL(r=request,f='edit_item', args=[record_id]), _class="updateDialog")}} And then I've got javascript to intercept the clicks on the edit icon, figure out which record's edit page it links to and instead load that edit form within a jqueryui dialog. //Manage the display of the dialog for editing details. $(function() { $("#edit_dialog").dialog({ width: 600, height: 355, modal: true, //hide: 'slide', autoOpen: false }); //opens the dialog whenever one of the edit icons is clicked $(document).on('click', 'a.updateDialog', function() { //get url to load from the clicked link's href var url = $(this).attr('href'); //get the datatable row ID that we're editing var nTr = $(this).closest("tr").get(0); // key line that gets the closest TR aPos = vol_table.fnGetPosition( nTr ); // gets the position within the datatable //augment the url with the row index (aPos) because need to be able refer to it in the server response to be able to update correct row's display url = url+'/'+aPos; //load up the actual form from server & embed it within the dialog's body element (edit_form_loader) $.web2py.component(url, 'edit_form_loader');//request web2py's ajax to reload the component with the URL for this specific item's info $('#edit_dialog').dialog('open');//show the dialog return false; }); }); Good Luck! ~Brian On Wednesday, June 18, 2014 9:45:08 AM UTC-5, Tomeu Roig wrote: > > I call a function that content a grid or smartgrid and need pass args and > (user_signature=True), how i can make it? > > now I use in controller response.js like: > > tab_history = """jQuery('#historial > a[href="#historico"]').click(function(){ > $.web2py.component("%s", target="historico"); > })""" % URL('albaranes', 'view_albs_cli.load', > args=[cliente_id,'historico'],user_signature=True) > response.js = tab_history > > It's works but i would like make the same in the view, it's possible? > > thanks. > > El lunes, 16 de junio de 2014 15:33:05 UTC+2, Anthony escribió: >> >> If you want to dynamically add a component in the browser, you cannot use >> the LOAD helper, which is a Python helper that is serialized on the server. >> Instead, use the $.web2py.component() Javascript function. Something like: >> >> >> >> >> >> Anthony >> >> On Friday, June 13, 2014 7:47:34 PM UTC-4, Omri Levy wrote: >>> >>> Hi , >>> >>> So I have a ticket system, and I want to allow user to edit the ticket >>> without leaving the page. >>> I don't want to LOAD the edit_page and hide it, but only load it once >>> user is clicking on the ticket body. >>> Another thing is, when user edits the ticket, he should again see >>> changes on the same page. >>> >>> Is this possible? I'm a bit confused, because LOAD works fine, but not >>> when using conditions with JS. >>> >>> Thanks. >>> >> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
I call a function that content a grid or smartgrid and need pass args and (user_signature=True), how i can make it? now I use in controller response.js like: tab_history = """jQuery('#historial a[href="#historico"]').click(function(){ $.web2py.component("%s", target="historico"); })""" % URL('albaranes', 'view_albs_cli.load', args=[cliente_id,'historico'],user_signature=True) response.js = tab_history It's works but i would like make the same in the view, it's possible? thanks. El lunes, 16 de junio de 2014 15:33:05 UTC+2, Anthony escribió: > > If you want to dynamically add a component in the browser, you cannot use > the LOAD helper, which is a Python helper that is serialized on the server. > Instead, use the $.web2py.component() Javascript function. Something like: > > > > > > Anthony > > On Friday, June 13, 2014 7:47:34 PM UTC-4, Omri Levy wrote: >> >> Hi , >> >> So I have a ticket system, and I want to allow user to edit the ticket >> without leaving the page. >> I don't want to LOAD the edit_page and hide it, but only load it once >> user is clicking on the ticket body. >> Another thing is, when user edits the ticket, he should again see changes >> on the same page. >> >> Is this possible? I'm a bit confused, because LOAD works fine, but not >> when using conditions with JS. >> >> Thanks. >> > -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Trying to use the LOAD helper, if a button is clicked
If you want to dynamically add a component in the browser, you cannot use the LOAD helper, which is a Python helper that is serialized on the server. Instead, use the $.web2py.component() Javascript function. Something like: Anthony On Friday, June 13, 2014 7:47:34 PM UTC-4, Omri Levy wrote: > > Hi , > > So I have a ticket system, and I want to allow user to edit the ticket > without leaving the page. > I don't want to LOAD the edit_page and hide it, but only load it once user > is clicking on the ticket body. > Another thing is, when user edits the ticket, he should again see changes > on the same page. > > Is this possible? I'm a bit confused, because LOAD works fine, but not > when using conditions with JS. > > Thanks. > -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.