Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

How to run time add classes, attributes, and styles for cells? #34

@masaoliou

Description

@masaoliou

I need to dynamically add classes, attributes, and styles for cells. According to examples row-template.html and dom-elements.html, it seems to me that sortable-table requires occurences of and <td></td> to be staticly coded like this:

<sortable-column name="fruit">Fruit</sortable-column>
<sortable-column name="alice">Alice</sortable-column>

<td style="width:10%;"><input type="number" value="{{record.row.alice}}" style="text-align:right;"></td>

My problem is that these occurences are unknown in design time. They are determined by input JSON data. Hence I have this clumsy design:

<sortable-table rowTemplate="rt">
    <template repeat="{{MyData.columns}}">
        <sortable-column class="{{color}}">{{title}}</sortable-column>
    </template>
    <template id="rt" bind="{{MyData.data as data}}">
        <template repeat="{{c,i in data}}">
            <td><input type="{{MyData.columns[i].type}}" required?="{{MyData.columns[i].required}}" value="{{record.row[i]}}" style="text-align:{{MyData.columns[i].type == 'number' ? 'right' : 'left'}};"></td>
        </template>
    </template>
</sortable-table>
<script>
document.querySelector("sortable-table").MyData={
    columns:[
        {title:"fruit",type:"text",color:"red",required:true}
        ,{title:"alice",type:"number",color:"blue",required:true}
        ,{title:"bill",type:"number",color:"yellow"}
        ,{title:"casey",type:"number",color:"green"}
    ]
    ,data:[
        ["apple",4,10,2],["banana",0,4,0],["grape",2,3,5],["pear",4,2,8],["strawberry",0,14,0]
    ]
};
</script>

Notice that I avoid adding column names in input JSON data in order to save some bandwidth.

My code has one big issue - the value entered by user in <input></input> loses 2-way data binding!

What is the correct design patten in my case?
Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions