How do I hide automatically generated child columns in web2py's SmartGrid?

35 views
Skip to first unread message

Andrew Rogers

unread,
Apr 24, 2020, 2:38:21 AM4/24/20
to web2py-users

I love the way web2py smartgrid creates automatic child links to referenced tables. But i can't find how to customise them.

I want to show only some of the child table links (see below). I know i can eliminate referenced tables by specifying the `linked_tables` option. And I can make my own links  using the option to make new `links`. And I can use `fields` to hide columns for the main table. 

But how do I hide one or more of the automatically generated child columns for the tables that *are* included in `linked_tables`?

And is it possible to change the link text?



child_links.png

Jim S

unread,
Apr 24, 2020, 8:51:31 AM4/24/20
to web2py-users
This is pretty ugly, but I think it should work if you're interested in fixing this with jquery in your template.

I use this technique to hide columns based on other things going on with the page, but should work in your situation too.  I haven't tested the re-labeling the column heading so the 10th line may need some tweaking...
{{extend 'layout.html'}}
<script type="text/javascript">
    $
(document).ready(function() {
       
{{if not request.args or not request.args[0] in ('new', 'edit', 'view'):}}
           
var rows = $('.web2py_htmltable > table > tbody > tr');
            rows
.each(function(index) {
                $
('td:nth-child(4)', this).hide();
           
})
            $
('th:nth-child(4)', this).hide();
            $
('th:nth-child(4)', this).val('Column Heading');
       
{{pass}}
   
});
</script>

AGRogers

unread,
Apr 28, 2020, 8:26:43 PM4/28/20
to web...@googlegroups.com
Many thanks Jim. Good idea. That should work for me fine. 
Cheers

--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/aa3d812e-2a1a-4907-b11e-f0c8f3a35179%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages