Skip to content

Commit 9a97900

Browse files
author
Tim Berners-Lee
committed
Add sort column and direction to table widget options
1 parent c9b9925 commit 9a97900

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/table.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ module.exports = function renderTableViewPane (doc, options) {
473473
}
474474
if (this.predicate) {
475475
if (this.predicate.sameTerm(ns.rdf('type')) && this.superClass) {
476-
return utils.label(this.superClass)
476+
return utils.label(this.superClass, true) // do initial cap
477477
}
478478
return utils.label(this.predicate)
479479
} else if (this.variable) {
@@ -647,6 +647,18 @@ module.exports = function renderTableViewPane (doc, options) {
647647
return resultDiv
648648
}
649649

650+
// Find the column for a given variable
651+
652+
function getColumnForVariable (columns, variableNT) {
653+
for (const predicateUri in columns) {
654+
var column = columns[predicateUri]
655+
if (column.variable.toNT() === variableNT) {
656+
return column
657+
}
658+
}
659+
return null
660+
}
661+
650662
// Find the column for a given predicate, creating a new column object
651663
// if necessary.
652664

@@ -1647,16 +1659,11 @@ module.exports = function renderTableViewPane (doc, options) {
16471659
}
16481660
}
16491661

1650-
/*
1651-
for (let i=0; i< rows.length; i++) {
1652-
rows[i].originalValues = rows[i].values
1653-
rows[i].values = {}
1654-
// oldStyle = rows[i]._htmlRow.getAttribute('style') || ''
1655-
rows[i]._htmlRow.style.background = '#ffe'; //setAttribute('style', ' background-color: #ffe;')//
1656-
applyColumnFilters(rows, columns); // @@ TBL added this
1657-
// Here add table clean-up, remove "loading" message etc.
1658-
}
1659-
*/
1662+
if (options.sortBy) { // @@ for each column check needs sorting
1663+
const column = getColumnForVariable(columns, options.sortBy)
1664+
literalSort(rows, column, options.sortReverse)
1665+
}
1666+
16601667
if (options.onDone) options.onDone()
16611668
}
16621669
kb.query(query, onResult, undefined, onDone)

0 commit comments

Comments
 (0)