stevenrskelton / sortable-table

Polymer Web Component that generates a sortable <table> from inlined or AJAX JSON, JSON5, and arrays.
https://stevenrskelton.github.io/sortable-table/
MIT License
196 stars 37 forks source link

Dynamic columns with cellTemplates. #23

Closed gertcuykens closed 9 years ago

gertcuykens commented 9 years ago

This works

            var data = [
                {fruit: 'apple', alice: 4, bill: 10, casey: 2, average: 5.3, total: 16 },
                {fruit: 'banana', alice: 0, bill: 4, casey: 0, average: 1.3, total: 4 },
                {fruit: 'grape', alice: 2, bill: 3, casey: 5, average: 3.3, total: 10 },
                {fruit: 'pear', alice: 4, bill: 2, casey: 8, average: 4.6, total: 14 },
                {fruit: 'strawberry', alice: 0, bill: 14, casey: 1, average: 5, total: 15 }
            ];

            var columns = [
                {name:'fruit', cellTemplate: 'fruitsTemplate'},
                {name:'alice'},
                {name:'bill'},
                {name:'casey'},
                {name:'average'},
                {name:'total'}
            ];

But would be nice if you can do the same thing with dynamic columns and only specify the columns that need a cellTemplate.

            var data = [
                {fruit: 'apple', alice: 4, bill: 10, casey: 2, average: 5.3, total: 16 },
                {fruit: 'banana', alice: 0, bill: 4, casey: 0, average: 1.3, total: 4 },
                {fruit: 'grape', alice: 2, bill: 3, casey: 5, average: 3.3, total: 10 },
                {fruit: 'pear', alice: 4, bill: 2, casey: 8, average: 4.6, total: 14 },
                {fruit: 'strawberry', alice: 0, bill: 14, casey: 1, average: 5, total: 15 }
            ];

            var columnsT = [
                {name:'fruit', cellTemplate: 'fruitsTemplate'},
            ];
stevenrskelton commented 9 years ago

This is a tough call, a lot of use-cases have data fields that aren't to be displayed.

For example, computed columns could combine 1 or more fields into a single displayed column. Or the data might be coming unfiltered from another source, and it may be important not to break the 2-way binding by copying it into another more selective array.

I'll keep this idea in mind and re-open if I can find a way to implement it without breaking anything.