This is little bit tricky but works. 

Thanks for help and useful explanation.


On Sunday, December 9, 2018 at 7:22:03 PM UTC+1, Anthony wrote:
>
> There is a shortcoming in the smartgrid code where if an argument is a 
> dictionary, it expects each of the keys to be table names -- it then 
> attempts to extract the item matching the current table name and pass that 
> as the relevant argument to SQLFORM.grid. Of course, this approach breaks 
> down when the argument itself is intended to be a dictionary. The only 
> workaround is to provide a dictionary that includes a copy of your 
> export_classes dict for every table you want to include in smartgrid:
>
> export_classes = dict(json=False, html=False, tsv=False, xml=False,
>                       csv_with_hidden_cols=False, tsv_with_hidden_cols=
> False)
> grid = SQLFORM.smartgrid(..., exportclasses=dict(table1=export_classes, 
> table2=export_classes, ...))
>
> Or you could do something like this:
>
> class SingleItemDict(dict):
>     def __init__(self, value):
>         self.value = value
>     
>     def __getitem__(self, key):
>         return self.value
>
>     def __contains__(self, key):
>         return True
>
> export_classes = SingleItemDict(dict(json=False, html=False, tsv=False, 
> xml=False,                                                                
>          csv_with_hidden_cols=False, tsv_with_hidden_cols=False))
> grid = SQLFORM.smartgrid(..., exportclasses=export_classes)
>
> The idea of the SingleItemDict class is to store just a single value and 
> allow it to be accessed via any key (the __contains__ method ensures the 
> "in" operator will work as well). Essentially, it is tricking the smartgrid 
> code into finding what it is looking for.
>
> Anthony
>
>
> On Tuesday, November 14, 2017 at 12:57:25 AM UTC-5, Peter wrote:
>>
>> I need only csv export method from  SQLFORM.smartgrid so I want to 
>> disable default export methods. Seems to me that 
>> SQLFORM.smartgrid(exportclasses=dict(json=False)) doesn't work in newer 
>> versions of web2py (2.14.6). 
>>
>> My code:
>>
>> export_classes = dict(json=False, html=False,
>>                       tsv=False, xml=False, csv_with_hidden_cols=False,
>>                       tsv_with_hidden_cols=False)
>>
>> table = SQLFORM.smartgrid(db.tableexample, user_signature=False, 
>> showbuttontext=False,
>>             links=links, linked_tables=[],
>>             editable = True, deletable = True,
>>             exportclasses=export_classes)
>>
>>
>>
>>
>> Am I  wrong?
>>
>> In version 2.10.3 this works just fine.
>>
>

-- 
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.

Reply via email to