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

Commit

Permalink
Add support for non-sortable columns, and columns with empty titles.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenrskelton committed Nov 13, 2014
1 parent ac17062 commit 65e1a1f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ <h3><a name="user-content-columns" class="anchor" href="#columns" aria-hidden="t
<td><code>null</code></td>
<td><em>See</em> <a href="#column--footertemplate">Column § footerTemplate</a></td>
</tr>
<tr>
<td><code>sortable</code></td>
<td><em>boolean</em></td>
<td><code>null</code></td>
<td>If <code>false</code>, column cannot be sorted by clicking on the column header.</td>
</tr>
</tbody>
</table>
</body>
Expand Down
15 changes: 10 additions & 5 deletions sortable-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
on-dragleave="{{handleTHDragLeave}}"
on-drop="{{handleTHDrop}}"
on-dragend="{{handleTHDragEnd}}"
>{{!(column.title) ? column.name : column.title}}</th>
>{{column.title == null ? column.name : column.title}}</th>
</template>
</template>
</tr>
Expand Down Expand Up @@ -483,8 +483,11 @@
if(!name || name === '') name = index;
if(String(name).indexOf(' ') > -1) alert('Column name `'+name+'` contains an illegal character (` `)');
var title = n.getAttribute('title');
if(!title || title === '') title = n.textContent.trim();
if(title === '') title = name;
if(title === null){
title = n.textContent.trim();
if(title === '') title = name;
}
var sortable = n.getAttribute('sortable');
var formula = n.getAttribute('formula');
if(formula){
var match = formula.match(/function[^\(]*\(([^\)]*)\)[^\{]*{([^\}]*)\}/);
Expand All @@ -504,7 +507,7 @@
}else alert('Could not load formula `'+ formula +'` for column `' + name + '`');
}
return {
name: name, title: title, formula: formula,
name: name, title: title, formula: formula, sortable: sortable,
cellTemplate: n.getAttribute('cellTemplate'),
headerTemplate: n.getAttribute('headerTemplate'),
footerTemplate: n.getAttribute('footerTemplate')
Expand Down Expand Up @@ -895,7 +898,9 @@
* Template Functions
*/
changeSort: function(e,p){
if(!this.userSort && e.target.templateInstance.model.column){
if(!this.userSort && e.target.templateInstance.model.column &&
e.target.templateInstance.model.column.sortable !== false &&
e.target.templateInstance.model.column.sortable !== 'false'){
var clickedSortColumn = e.target.templateInstance.model.column.name;
if(clickedSortColumn === this.sortColumn){
//column already sorted, reverse sort
Expand Down

0 comments on commit 65e1a1f

Please sign in to comment.