· 8 years ago · Apr 08, 2018, 12:16 AM
1## table row view
2
3SC.TableRowView = SC.ListItemView.extend(
4/** @scope SC.TableRowView.prototype */ {
5
6 render: function() {
7 var html = [] ;
8 var content = this.get('content') ;
9 var del = this.displayDelegate ;
10
11 // get the column information of this record
12 // what records to display and in what order
13 // (labelKey && content && content.get)
14 if(content && content.get){
15 var tempColumnNames = content.get('properties');
16 var tempColumnOrder = this.getDelegateProperty(del,'columnOrder');
17 var tempColumnsToDisplay = this.getDelegateProperty(del,'columnsToDisplay');
18
19
20 // if tempColumnsToDisplay is empty, show all columns ??
21 //if(tempColumnsToDisplay.length < 1){
22 // tempColumnsToDisplay ==
23 //}
24
25 // create the array of elements to display
26
27 for(orderindex=0;orderindex<tempColumnOrder.length;orderindex++){
28 // first do the order
29 var displayColumn = false;
30 var validProperty = false;
31 // check whether to display
32 for(displayindex=0;displayindex<tempColumnsToDisplay.length;displayindex++){
33 if(tempColumnsToDisplay[displayindex] === tempColumnOrder[orderindex]){
34 displayColumn = true;
35 }
36 }
37 // check whether exists
38 for(propertyindex=0;propertyindex<tempColumnNames.length;propertyindex++){
39 if(tempColumnNames[propertyindex] === tempColumnOrder[orderindex]){
40 validProperty = true;
41 }
42 }
43 // if exists
44 if(displayColumn && validProperty){
45 var cellContent = content.get(tempColumnOrder[orderindex]);
46 html.push(this.renderRowHtml(cellContent));
47 }
48 }
49 }
50
51 html = html.join('') ;
52 if (html != this._lastRenderedHtml) {
53 this._lastRenderedHtml = html ;
54 this.set('innerHTML', html) ;
55 }
56 },
57
58 // '<span style="sc-table-row <column>"></span>'
59
60 renderRowHtml: function(label){
61 var html = [];
62 html.push('<span class="sc-table-cell">') ;
63 html.push(label || '') ;
64 html.push('</span>') ;
65 return html.join('');
66 }
67
68});
69
70## addition to tableview
71
72 exampleView: SC.TableRowView,
73
74 columnOrder: [], // array with elements in order, if the column name is not in the array, it will
75
76 columnsToDisplay: [], // array with columns to display
77
78 showColumnNames: true, // show column names if desired