I posted on this on my 
blog<http://ochiba77.blogspot.com/2012/10/web2py-grid-with-export-dropdown.html?showComment=1351174654911#c5334545878916593563>
 and 
someone pointed that it will get ticket when clicking View button. Do you 
know how to fix?

Problem looks like here.
export_menu_links = original_export_menu.elements('a')

1.
2.
3.
4.
5.
6.

Traceback (most recent call last):
  File "C:\web2py\gluon\restricted.py", line 209, in restricted
    exec ccode in environment
  File "C:\web2py\applications\grid\views\default/index.html", line 82, in 
<module>
AttributeError: 'NoneType' object has no attribute 'elements'



73.
74.
75.
76.
77.
78.
79.
80.
81.
82.

83.
84.
85.
86.
87.
88.
89.
90.
91.
92.

    pass
response.write('\n\n        <div class="', escape=False)
response.write(middle_columns)
response.write('">\n            ', escape=False)
response.write('\n            ', escape=False)
response.write('\r\n', escape=False)
w2p_grid_tbl = grid.element('table')
if w2p_grid_tbl:
    original_export_menu = grid.element('div.w2p_export_menu')
    export_menu_links = original_export_menu.elements('a')

    export_menu_items = []
    for link in export_menu_links:
        item = LI(link)
        export_menu_items.append(item)
        pass
    new_export_menu = DIV(
    A( T('Exports'),
    SPAN(_class='caret'),
    _href='#',
    _class='btn dropdown-toggle',






On Tuesday, October 23, 2012 8:38:54 AM UTC-5, Omi Chiba wrote:
>
> It works! Thank you for sharing your code.
>
>
>
> On Monday, October 22, 2012 5:00:19 PM UTC-5, Paolo Caruccio wrote:
>>
>> My fault. I extrapoled the code from more complex one.
>>
>> Try this:
>>
>> {{extend 'layout.html'}}
>> {{
>> w2p_grid_tbl = grid.element('table')
>> if w2p_grid_tbl:
>>  original_export_menu = grid.element('div.w2p_export_menu')
>>  export_menu_links = original_export_menu.elements('a')
>>  export_menu_items = []
>>  for link in export_menu_links:
>>      item = LI(link)
>>      export_menu_items.append(item)
>>  pass
>>  new_export_menu = DIV(
>>                       A( T('Exports'),
>>                          SPAN(_class='caret'),
>>                          _href='#',
>>                          _class='btn dropdown-toggle',
>>                          **{'_data-toggle':"dropdown"}
>>                         ),
>>                       UL(*export_menu_items,
>>                          _class='dropdown-menu'
>>                         ),
>>                     _class='w2p_export_menu btn-group'
>>                     )
>>  export_menu = grid.element('div.w2p_export_menu',replace=new_export_menu
>> )
>> pass
>> }}
>>
>> {{=grid}}
>>
>> Of course you could modify the DOM directly in the controller.
>>
>>
>>
>> Il giorno lunedì 22 ottobre 2012 22:56:48 UTC+2, Omi Chiba ha scritto:
>>>
>>> Wow! This is exactly what I wanted. I hope this will be the default 
>>> layout for grid.
>>>
>>> I copy and pasted your code between {{extend 'layout.html'}} and 
>>> {{=gird}}, then export labels are now disappeard...
>>> Maybe you should check your code with the latest (2.1.1). 
>>>
>>> {{left_sidebar_enabled,right_sidebar_enabled=False,('message' in 
>>> globals())}}
>>> {{extend 'layout.html'}}
>>> {{
>>> w2p_grid_tbl = grid.element('table')
>>> if w2p_grid_tbl:
>>>  export_menu = grid.element('div.w2p_export_menu')
>>>  export_menu_links = export_menu.elements('a')
>>>  export_menu_items = []
>>>  for link in export_menu_links:
>>>      item = LI(link)
>>>      export_menu_items.append(item)
>>>  pass
>>>  export_menu = grid.element('div.w2p_export_menu',replace=None)
>>>  new_export_menu = DIV(
>>>                       A( T('Exports'),
>>>                          SPAN(_class='caret'),
>>>                          _href='#',
>>>                          _class='btn dropdown-toggle',
>>>                          **{'_data-toggle':"dropdown"}
>>>                         ),
>>>                       UL(*export_menu_items,
>>>                          _class='dropdown-menu'
>>>                         ),
>>>                     _class='w2p_export_menu btn-group'
>>>                     )
>>> pass
>>> }}
>>>
>>> {{=grid}}
>>>
>>>
>>>
>>>
>>> On Monday, October 22, 2012 2:10:53 PM UTC-5, Paolo Caruccio wrote:
>>>>
>>>> For grid export menu I'm happy with below method
>>>>
>>>> In the views/*.html file where is your grid put on top (just below 
>>>> extend layout command)  the following code:
>>>>
>>>> {{
>>>> w2p_grid_tbl = grid.element('table')
>>>> if w2p_grid_tbl:
>>>>  export_menu = grid.element('div.w2p_export_menu')
>>>>  export_menu_links = export_menu.elements('a')
>>>>  export_menu_items = []
>>>>  for link in export_menu_links:
>>>>      item = LI(link)
>>>>      export_menu_items.append(item)
>>>>  pass
>>>>  export_menu = grid.element('div.w2p_export_menu',replace=None)
>>>>  new_export_menu = DIV(
>>>>                       A( T('Exports'),
>>>>                          SPAN(_class='caret'),
>>>>                          _href='#',
>>>>                          _class='btn dropdown-toggle',
>>>>                          **{'_data-toggle':"dropdown"}
>>>>                         ),
>>>>                       UL(*export_menu_items,
>>>>                          _class='dropdown-menu'
>>>>                         ),
>>>>                     _class='w2p_export_menu btn-group'
>>>>                     )
>>>> pass
>>>> }}
>>>>
>>>> In the attached picture you can see how the exports menu is rendered 
>>>> using css bootstrap framework.
>>>>
>>>> The method is based on Server-side DOM and parsing (
>>>> http://web2py.com/books/default/chapter/29/05#Server-side-DOM-and-parsing) 
>>>> and it uses the elements argument "replace" (new beatiful and powerful - 
>>>> in 
>>>> my opinion - feature). For reference you could read 
>>>> https://groups.google.com/forum/?fromgroups=#!topic/web2py/fbYZXoIOkCY
>>>>
>>>> I hope this will help you.
>>>>
>>>>  
>>>>
>>>> Il giorno lunedì 22 ottobre 2012 17:15:37 UTC+2, Omi Chiba ha scritto:
>>>>>
>>>>> New export function on grid has many choices but I need to keep the 
>>>>> old format. (Export button for csv) because...
>>>>>
>>>>> - I'm using the gird for users (Maybe this format is good for us but 
>>>>> not users.)
>>>>> - Current export options layout is not pretty (I prefer button with 
>>>>> dropdown list)
>>>>> - I don't want users to see hidden columns
>>>>>
>>>>> Is there any option available for me?
>>>>>
>>>>>

-- 



Reply via email to