Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rendering hybrid_properties in tables #118

Closed
WolfgangFahl opened this issue Jan 24, 2021 · 2 comments · Fixed by #204
Closed

rendering hybrid_properties in tables #118

WolfgangFahl opened this issue Jan 24, 2021 · 2 comments · Fixed by #204
Labels
enhancement New feature or request table

Comments

@WolfgangFahl
Copy link

WolfgangFahl commented Jan 24, 2021

I am trying to display hybrid properties in a table but it does not work out of the box.
see http://fb4demo.bitplan.com/datatable

what is needed to get this working?

grafik

def datatable(self):
        '''
        test data table
        '''
        icons=BootstrapIcon.query.all()
        return render_template('datatable.html',listOfDicts=icons)
 
class BootstrapIcon(db.Model):
    id=Column(types.String(30), primary_key=True)
    index=Column(types.Integer)
    
    @hybrid_property
    def url(self):
        myUrl="https://icons.getbootstrap.com/icons/%s/" % self.id
        return myUrl
    
    @hybrid_property
    def link(self):
        myLink=Link(self.url,self.id)
        return myLink
    
    @hybrid_property
    def icon(self):
        myIcon=Icon(self.id)
        myIcon.userdata['#']=self.index
        return myIcon
@WolfgangFahl
Copy link
Author

WolfgangFahl commented Jan 24, 2021

I've worked around the issue by using my own table macro and preparing a list of dicts.

 def datatable(self):
        '''
        test data table
        '''
        icons=BootstrapIcon.query.all()
        dictList=[]
        for icon in icons:
            dictList.append(icon.asDict())
        return render_template('datatable.html',listOfDicts=dictList)
...
  def asDict(self):
        myDict={
            'link': self.link,
            'icon': self.icon
        }
        return myDict

grafik

{# table for dict list #}
{% macro table4DictList(dictList) -%}
<table class="table table-bordered table-hover">
  <!-- table header -->
  {% if dictList %}
  <thead class="thead-light">
  	<tr>
  		<th>#</th>
    	{% for key in dictList[0] %}
    	<th> {{ key }} </th>
    	{% endfor %}
 	</tr>
  <thead>
  <tbody>	
    <!-- table rows -->
    {% for dict_item in dictList %}
    <tr>
       <td> {{loop.index}} </td>
       {% for value in dict_item.values() %}
       <td>  {{ value|safe }} </td>
       {% endfor %}
    </tr>
    {% endfor %}
  </tbody>  
  {% endif %}
</table>
{%- endmacro %}

@greyli greyli added table enhancement New feature or request labels Jun 10, 2021
@PanderMusubi
Copy link
Collaborator

Also need rendering cell data that is an URL (starting with https:// or http://) as a clickable link in the table. Also with an option for the entire table that adds opening in a new tab with target="_blank".

Any progress on this issue? Would like to help out if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request table
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants