Skip to content

Commit

Permalink
Merge pull request #226 from fabd/fix/224-flashcard-list-duplicate-it…
Browse files Browse the repository at this point in the history
…ems-when-sorting-by-box

Fix #224: add a secondary sort to solve duplicate rows in Flashcard List paging
  • Loading branch information
fabd authored Dec 10, 2021
2 parents 616e641 + 9c5326a commit d67755e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function execute($request)
$this->table = new uiSelectTable(new FlashcardListBinding(), $this->pager->getSelect(), $request->getParameterHolder());
$this->table->configure([
'sortColumn' => $queryParams[uiSelectTable::QUERY_SORTCOLUMN],
'sortColumnTwo' => 'seq_nr',
'sortOrder' => $queryParams[uiSelectTable::QUERY_SORTORDER]
]);

Expand Down
20 changes: 16 additions & 4 deletions src/lib/uiparts/uiSelectTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* in each column head.
*
* Methods that can be used in view template:
* getTableHead() Return HTML for the <thead> section
* getTableBody() Return HTML for the <tbody> section
*
* getTableHead() Return HTML for the <thead> section
* getTableBody() Return HTML for the <tbody> section
*
* TODO
* - Only print 7 chars of the checksum for row id validation purposes,
Expand Down Expand Up @@ -70,6 +71,9 @@ class uiSelectTable

// default sort column (null will be set to first defined column)
'sortColumn' => null,

// use a secondary sort to solve duplicate entries when paging results
'sortColumnTwo' => null,

// default sort order
'sortOrder' => 0,
Expand Down Expand Up @@ -430,8 +434,16 @@ private function applySorting(coreDatabaseSelect $select)
$this->sortOrder = intval($this->request->get(self::QUERY_SORTORDER, $this->settings['sortOrder']));
$this->sortOrder = $this->sortOrder % count($this->sortOrders);

// there is only one column so we quote here, ideally should be quoted in coreDatabaseSelect
return $select->order('`'.$this->sortColumn.'` '.$this->sortOrders[$this->sortOrder]);
// make sure to quote sort columns, as they can come from url query params
$orderCols = "`{$this->sortColumn}` {$this->sortOrders[$this->sortOrder]}";

// secondary sort order
$sortColumnTwo = $this->settings['sortColumnTwo'];
if ($sortColumnTwo && $sortColumnTwo !== $this->sortColumn) {
$orderCols .= ", `{$sortColumnTwo}`";
}

return $select->order($orderCols);
}

/**
Expand Down
36 changes: 19 additions & 17 deletions src/lib/uiparts/uiSelectTableBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@
/**
* uiSelectTableBinding configures the uiSelectTable component.
*
* Configuration (properties of the configuration object returned by getConfig():
* Configuration object returned by getConfig():
*
* 'settings':
* editable: <boolean> Output html structure for editable data (uiforms, unfinished)
* primaryKey: <string|array> One or multiple primary keys, very important for editable data
* sortColumn: <string> Initial sort column
* sortOrder: <0|1> Initial sort order
* rows_per_page: <int> Defaults to 10 (cf. uiSelectTable)
* settings:
*
* 'columns':
* editable <boolean> Output html structure for editable data (uiforms, unfinished)
* primaryKey <string|array> One or multiple primary keys, very important for editable data
* sortColumn <string> Initial sort column
* sortColumnTwo <string> Secondary sort column, defaults to ASC
* sortOrder <0|1> Initial sort order
* rows_per_page <int> Defaults to 10 (cf. uiSelectTable)
*
* An array of column definitions:
* columns:
*
* caption: <string> Column head title
* width: <int> Html width attribute (percent)
* cssClass: <string> Css class to apply on this column's cells
* colData: <string> Column used for display, sort and updates by default.
* (An array of column definitions)
*
* caption <string> Column head title
* width <int> Html width attribute (percent)
* cssClass <string> Css class to apply on this column's cells
* colData <string> Column used for display, sort and updates by default.
* colData is escaped for display!
* If not set, colDisplay may be used, and the column is not sortable.
* colDisplay: <string> If set, this will be the display value, while colData is used for sorting.
* colDisplay <string> If set, this will be the display value, while colData is used for sorting.
* The display value is NOT escaped!
* colSort: <string> If set, column to use for sorting.
* editable: <boolean> If true, editable and sent with post data. Default false.
* default: <string> Default value for new rows
* colSort <string> If set, column to use for sorting.
* editable <boolean> If true, editable and sent with post data. Default false.
* default <string> Default value for new rows
*
*
* @package UiParts
Expand Down

0 comments on commit d67755e

Please sign in to comment.