View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0004024 | Composr non-bundled addons | [All Projects] General / Uncategorised | public | 2020-01-03 20:23 | 2020-01-23 16:04 |
| Reporter | Chris Graham | Assigned To | Chris Graham | ||
| Severity | Feature-request | ||||
| Status | resolved | Resolution | fixed | ||
| Summary | 0004024: Issues with sortable tables block | ||||
| Description | 1) Cannot do default reverse sorting 2) Blank cells create various issues 3) IDs should be able to have dashes 4) When rows are filtered the bottom of the table looks ugly | ||||
| Additional Information | Patch attached. | ||||
| Tags | Roadmap: v11 | ||||
| Time estimation (hours) | 0.2 | ||||
| Sponsorship open | |||||
|
|
changes.diff (6,102 bytes)
diff --git a/sources_custom/blocks/main_sortable_table.php b/sources_custom/blocks/main_sortable_table.php
index f8d42c97..9c8a54ca 100644
--- a/sources_custom/blocks/main_sortable_table.php
+++ b/sources_custom/blocks/main_sortable_table.php
@@ -237,22 +237,6 @@ class Block_main_sortable_table
continue;
}
- foreach ($row as $j => $val) {
- foreach (is_array($transform) ? $transform : array($transform) as $_transform) {
- switch ($_transform) {
- case 'ucwords':
- $val = cms_mb_ucwords($val);
- break;
-
- case 'non-numeric-italics':
- if (!is_numeric($val)) {
- $row[$j] = protect_from_escaping('<em>' . escape_html($val) . '</em>');
- }
- break;
- }
- }
- }
-
$_rows[] = $row;
$i++;
@@ -400,6 +384,20 @@ class Block_main_sortable_table
foreach ($_rows as $i => &$row) {
foreach ($row as $j => &$value) {
$value = $this->apply_formatting($value, $headers[$j]['SORTABLE_TYPE']);
+
+ foreach (is_array($transform) ? $transform : array($transform) as $_transform) {
+ switch ($_transform) {
+ case 'ucwords':
+ $value = cms_mb_ucwords($value);
+ break;
+
+ case 'non-numeric-italics':
+ if ((!is_numeric($val)) && ($val != '')) {
+ $value = protect_from_escaping('<em>' . escape_html($value) . '</em>');
+ }
+ break;
+ }
+ }
}
$tooltip_values = array();
@@ -420,8 +418,13 @@ class Block_main_sortable_table
// Final render...
- $id = (preg_match('#^[\w_]+$#', $guid) != 0) ? $guid : uniqid('', false);
+ $id = (preg_match('#^[\w_\-]+$#', $guid) != 0) ? $guid : uniqid('', false);
+ $reverse_sorting = false;
+ if ((!empty($map['default_sort_column'])) && (substr($map['default_sort_column'], 0, 1) == '!')) {
+ $reverse_sorting = true;
+ $map['default_sort_column'] = substr($map['default_sort_column'], 1);
+ }
$_default_sort_column = max(0, empty($map['default_sort_column']) ? 0 : (intval(str_replace($letters, $numbers, $map['default_sort_column'])) - 1));
$default_sort_column = ($columns_display == array()) ? $_default_sort_column : array_search($_default_sort_column + 1, $columns_display);
if ($default_sort_column === false) {
@@ -432,7 +435,7 @@ class Block_main_sortable_table
return do_template('SORTABLE_TABLE', array(
'_GUID' => $guid,
'ID' => $id,
- 'DEFAULT_SORT_COLUMN' => strval($default_sort_column),
+ 'DEFAULT_SORT_COLUMN' => ($reverse_sorting ? '!' : '') . strval($default_sort_column),
'MAX' => strval($max),
'HEADERS' => $headers,
'ROWS' => $rows,
diff --git a/themes/default/javascript_custom/sortable_tables.js b/themes/default/javascript_custom/sortable_tables.js
index e489a94d..456fa7b0 100644
--- a/themes/default/javascript_custom/sortable_tables.js
+++ b/themes/default/javascript_custom/sortable_tables.js
@@ -731,6 +731,7 @@ var SortableTable = (function(){
// Scrape each row of each tbody
var bodies = t.tBodies;
if (bodies==null || bodies.length==0) { return; }
+ var mostRecentVisibleRow = null;
for (var i=0,L=bodies.length; i<L; i++) {
var tb = bodies[i];
for (var j=0,L2=tb.rows.length; j<L2; j++) {
@@ -780,19 +781,31 @@ var SortableTable = (function(){
if (!hasClass(row,'table-nofilter'))
row.style.display = hideRow?"none":"";
- if (row.className.replace(/^(\s*(first|last)\s*)*$/, '') == '') {
+ if (row.className.replace(/^(\s*(first|last)\s*)*$/, '') == '') { // If no other styles on the row
var classes = [];
- if (unfilteredrowcount == pagestart) {
- classes.push('first');
- }
- if (unfilteredrowcount == pageend) {
- classes.push('last');
+ if (!hideRow) {
+ if (unfilteredrowcount == pagestart) {
+ classes.push('first');
+ }
+ if (unfilteredrowcount == pageend) {
+ classes.push('last');
+ }
+ mostRecentVisibleRow = row;
}
row.className = classes.join(' ');
}
}
}
+ if (mostRecentVisibleRow !== null) {
+ var classes = [];
+ if (unfilteredrowcount == pagestart) {
+ classes.push('first');
+ }
+ classes.push('last');
+ mostRecentVisibleRow.className = classes.join(' ');
+ }
+
if (def(page)) {
// Check to see if filtering has put us past the requested page index. If it has,
// then go back to the last page and show it.
@@ -931,7 +944,12 @@ var SortableTable = (function(){
}
// Do auto-sort if necessary
if ((val = classValue(t,table.AutoSortColumnPrefix)) || (hasClass(t,table.AutoSortClassName))) {
- table.autosort(t,{'col':(val==null)?null:+val});
+ var autoSortArgs = {'col':(val==null)?null:window.parseInt(val.replace(/^!/,''))};
+ if (val.substr(0, 1) == '!') {
+ autoSortArgs['forcedirection'] = true;
+ autoSortArgs['desc'] = true;
+ }
+ table.autosort(t,autoSortArgs);
}
// Do auto-stripe if necessary
if (tdata.stripeclass && hasClass(t,table.AutoStripeClassName)) {
@@ -1077,4 +1095,4 @@ var SortableTable = (function(){
}
return table;
-})();
\ No newline at end of file
+})();
|
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2020-01-03 20:23 | Chris Graham | New Issue | |
| 2020-01-03 20:23 | Chris Graham | Tag Attached: Roadmap: v11 | |
| 2020-01-03 20:23 | Chris Graham | File Added: changes.diff | |
| 2020-01-03 20:24 | Chris Graham | Time estimation (hours) | => 0.2 |
| 2020-01-23 16:04 | Chris Graham | Assigned To | => Chris Graham |
| 2020-01-23 16:04 | Chris Graham | Status | non-assigned => resolved |
| 2020-01-23 16:04 | Chris Graham | Resolution | open => fixed |
| 2023-02-26 18:29 | Chris Graham | Category | General => General / Uncategorised |