[web2py] Re: Formatting GRID rows data based on the field value in database
Thanks Anthony, I have used the Images in the represent field for my application. On Sunday, June 8, 2014 7:59:52 AM UTC+5:30, Anthony wrote: Note, it would be more appropriate to use lambda status, row:, as the second value passed to the represent function is the Row object (not the Field object). You might be thinking of custom validators, which are passed the value being validated and the Field object. Anthony On Saturday, June 7, 2014 8:52:22 PM UTC-4, 黄祥 wrote: yes, you are right, my fault, my code only produce one color, thank you so much for your detail explaination, anthony. e.g. if 'product' in request.function : table.status.represent = lambda status, field: SPAN(status, _class = 'text-success' if status == 'Sold' else 'text-warning' if status == 'Hold' else 'text-error') best regards, stifan -- 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: Formatting GRID rows data based on the field value in database
def on_define_product(table): if 'product' in request.function : if table.signoff == 'No': table.signoff.represent = lambda signoff, field: SPAN(signoff, _class = 'text-error') elif table.signoff == 'Yes': table.signoff.represent = lambda signoff, field: SPAN(signoff, _class = 'text-success') Note, Sarbjit wants to format *each row* differently, depending on the values in the row. The above cannot do that. First, in the above function, table.signoff is a dal.Field object. The Field object does not have a value of No or Yes, so neither branch above will ever execute. Second, the relevant logic must be applied separately to each Row selected from the database, so the logic cannot go in an on_define function, which is called only once when the table is defined. Rather, the logic must go in the represent function itself, which is called separately for each Row. 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: Formatting GRID rows data based on the field value in database
yes, you are right, my fault, my code only produce one color, thank you so much for your detail explaination, anthony. e.g. if 'product' in request.function : table.status.represent = lambda status, field: SPAN(status, _class = 'text-success' if status == 'Sold' else 'text-warning' if status == 'Hold' else 'text-error') best regards, stifan -- 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: Formatting GRID rows data based on the field value in database
Note, it would be more appropriate to use lambda status, row:, as the second value passed to the represent function is the Row object (not the Field object). You might be thinking of custom validators, which are passed the value being validated and the Field object. Anthony On Saturday, June 7, 2014 8:52:22 PM UTC-4, 黄祥 wrote: yes, you are right, my fault, my code only produce one color, thank you so much for your detail explaination, anthony. e.g. if 'product' in request.function : table.status.represent = lambda status, field: SPAN(status, _class = 'text-success' if status == 'Sold' else 'text-warning' if status == 'Hold' else 'text-error') best regards, stifan -- 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: Formatting GRID rows data based on the field value in database
You can set the represent attribute for the fields you would like to format. Anthony On Friday, June 6, 2014 1:31:06 AM UTC-4, Sarbjit wrote: Hi, I am using GRID in my application, my requirement is that I want to display the field value in different color (RED/GREEN) OR I want to display the images (Tick Mark Image/Cross Mark Image) based upon the data in the field. e.g. (Sample example) Product_ID Product_TitleProduct_SignOff 1 XZ Yes 2 AV Yes 3 AD NO I want it to be viewed in gird as : Product_ID Product_TitleProduct_SignOff 1 XZ Yes 2 AV Yes 3 AD NO OR any other additional indicator could be added such that the rows with Signoff value as NO could be easily identified (or highlighted). I was wondering, if I could use some images there (Green color Tick mark or Red color Cross mark) in the grid. Since, I am not having much experience using web2py, can someone please help me to achieve this. Thanks Sarbjit -- 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: Formatting GRID rows data based on the field value in database
Thanks Anthony, Can you please provide a small example. On Friday, June 6, 2014 6:03:29 PM UTC+5:30, Anthony wrote: You can set the represent attribute for the fields you would like to format. Anthony On Friday, June 6, 2014 1:31:06 AM UTC-4, Sarbjit wrote: Hi, I am using GRID in my application, my requirement is that I want to display the field value in different color (RED/GREEN) OR I want to display the images (Tick Mark Image/Cross Mark Image) based upon the data in the field. e.g. (Sample example) Product_ID Product_TitleProduct_SignOff 1 XZ Yes 2 AV Yes 3 AD NO I want it to be viewed in gird as : Product_ID Product_TitleProduct_SignOff 1 XZ Yes 2 AV Yes 3 AD NO OR any other additional indicator could be added such that the rows with Signoff value as NO could be easily identified (or highlighted). I was wondering, if I could use some images there (Green color Tick mark or Red color Cross mark) in the grid. Since, I am not having much experience using web2py, can someone please help me to achieve this. Thanks Sarbjit -- 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: Formatting GRID rows data based on the field value in database
db.define_table('mytable', Field('Product_SignOff', represent=lambda v, r: SPAN(v, _class='green' if v == 'Yes' else 'red')), ...) On Friday, June 6, 2014 9:52:58 AM UTC-4, Sarbjit wrote: Thanks Anthony, Can you please provide a small example. On Friday, June 6, 2014 6:03:29 PM UTC+5:30, Anthony wrote: You can set the represent attribute for the fields you would like to format. Anthony On Friday, June 6, 2014 1:31:06 AM UTC-4, Sarbjit wrote: Hi, I am using GRID in my application, my requirement is that I want to display the field value in different color (RED/GREEN) OR I want to display the images (Tick Mark Image/Cross Mark Image) based upon the data in the field. e.g. (Sample example) Product_ID Product_TitleProduct_SignOff 1 XZ Yes 2 AV Yes 3 AD NO I want it to be viewed in gird as : Product_ID Product_TitleProduct_SignOff 1 XZ Yes 2 AV Yes 3 AD NO OR any other additional indicator could be added such that the rows with Signoff value as NO could be easily identified (or highlighted). I was wondering, if I could use some images there (Green color Tick mark or Red color Cross mark) in the grid. Since, I am not having much experience using web2py, can someone please help me to achieve this. Thanks Sarbjit -- 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: Formatting GRID rows data based on the field value in database
another way around : if table.Product_SignOff == 'Yes': table.Product_SignOff.represent = lambda Product_SignOff, field: SPAN(Product_SignOff, _class = 'text-error') elif table.Product_SignOff == 'No': table.Product_SignOff.represent = lambda Product_SignOff, field: SPAN(Product_SignOff, _class = 'text-success') when tested with anthony code above (html inspect elements) : span class='green' Yes /span no errors occured, the output is not expected, still have a black font color. best regards, stifan -- 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: Formatting GRID rows data based on the field value in database
another way around : if table.Product_SignOff == 'Yes': table.Product_SignOff.represent = lambda Product_SignOff, field: SPAN(Product_SignOff, _class = 'text-error') elif table.Product_SignOff == 'No': table.Product_SignOff.represent = lambda Product_SignOff, field: SPAN(Product_SignOff, _class = 'text-success') No, the above won't work. table.Product_SignOff is a Field object, not a Row value, so you cannot test whether it equals Yes or No. Instead, you must put all the logic in the represent function. when tested with anthony code above (html inspect elements) : span class='green' Yes /span no errors occured, the output is not expected, still have a black font color. I was just using example green and red CSS classes. Of course, you would actually have to define those classes in your CSS file to change the text to green or red. 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: Formatting GRID rows data based on the field value in database
a, that's what i'm lacked off, not created the css classes for green and red classes. thank you so much, anthony. btw, the piece of code above is not completed, here is the complete code : e.g. def on_define_product(table): if 'product' in request.function : if table.signoff == 'No': table.signoff.represent = lambda signoff, field: SPAN(signoff, _class = 'text-error') elif table.signoff == 'Yes': table.signoff.represent = lambda signoff, field: SPAN(signoff, _class = 'text-success') db.define_table('product', Field('title'), Field('signoff'), on_define = on_define_product, format = '%(title)s') tested work in smartgrid, anthony code is more simple (this is just another way to accomplish it). best regards, stifan -- 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.