diff --git a/includes/ProgressTableProcessor.php b/includes/ProgressTableProcessor.php index 96ee2a0..348117e 100644 --- a/includes/ProgressTableProcessor.php +++ b/includes/ProgressTableProcessor.php @@ -174,7 +174,7 @@ private function validateDataRowIds(): bool { foreach ( $dataRows as $row ) { $rowId = $this->extractDataRowId( $row ); if ( empty( $rowId ) ) { - $this->errorMessage = 'When unique-column-index is not provided, + $this->errorMessage = 'When unique-column-index is not provided, all data rows must have a data-row-id attribute.'; return false; } @@ -348,6 +348,9 @@ private function addCheckboxCellToRow( DOMElement $row, int $rowIndex ): void { $cell = $this->dom->createElement( 'td' ); $cell->setAttribute( 'class', self::CHECKBOX_CELL_CLASS ); + // set the initial sortable value to 0 (does nothing if the table isn't sortable) + // when the JS runs, it will change this to 1 for tracked cells + $cell->setAttribute( 'data-sort-value', 0 ); $cell->appendChild( $checkboxDiv ); $row->insertBefore( $cell, $row->firstChild ); diff --git a/resources/index.js b/resources/index.js index 82ac3ce..7bdefd4 100644 --- a/resources/index.js +++ b/resources/index.js @@ -152,8 +152,19 @@ var ProgressTracker = { // remove the disable attribute from the checkbox so that it can be actioned // this happens irrespective of whether the checkbox is checked or not checkbox.disabled = false; + + // if this row is tracked, change the sortable value to 1 to allow sorting + // (even if the table isn't sortable) + let sortVal = isChecked ? 1 : 0; + let $cell = $( checkbox ).closest( 'td' ); + + if ( $cell.length ) { + $cell.attr( 'data-sort-value', sortVal ); + $cell.data( 'sortValue', sortVal ); + } } }.bind( this ) ); + $( table ).trigger('update'); }, /**