1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 02:04:35 +02:00

Update ProcessPageLister to identify when columns are not sortable

This commit is contained in:
Ryan Cramer
2022-02-04 14:23:20 -05:00
parent ebb4663b84
commit 54d820e622
5 changed files with 58 additions and 16 deletions

File diff suppressed because one or more lines are too long

View File

@@ -114,13 +114,17 @@ var ProcessLister = {
* *
*/ */
columnSort: function() { columnSort: function() {
$(this).find("span").remove();
var name = $(this).find('b').text(); if($(this).hasClass('not_sortable')) return false;
$(this).find('span').remove();
var $b = $(this).find('b');
var name = $b.text();
var val = $("#lister_sort").val(); var val = $("#lister_sort").val();
if(val == name) name = '-' + name; // reverse if(val == name) name = '-' + name; // reverse
if(name.length < 1) name = val; if(name.length < 1) name = val;
$("#lister_sort").val(name); $('#lister_sort').val(name);
ProcessLister.submit(); ProcessLister.submit();
}, },

File diff suppressed because one or more lines are too long

View File

@@ -1224,6 +1224,23 @@ class ProcessPageLister extends Process implements ConfigurableModule {
return $label; return $label;
} }
/**
* Is field or field+subfield sortable in the table?
*
* @param Field $field
* @param string $subfield
* @return bool
* @since 3.0.194
*
*/
protected function isSortableCol(Field $field, $subfield = '') {
if($subfield === 'data' || empty($subfield) || $subfield === 'count') return true;
if($subfield === 'keys' || $subfield === 'xtra') return false;
$fieldtype = $field->type;
$schema = $fieldtype->getDatabaseSchema($field);
return isset($schema[$subfield]);
}
/** /**
* Build the Lister table containing results * Build the Lister table containing results
* *
@@ -1232,15 +1249,19 @@ class ProcessPageLister extends Process implements ConfigurableModule {
* *
*/ */
protected function buildListerTable(PageArray $results) { protected function buildListerTable(PageArray $results) {
$sanitizer = $this->wire()->sanitizer;
$modules = $this->wire()->modules;
$fields = $this->wire()->fields;
/** @var Languages $languages */ /** @var Languages $languages */
$columns = $this->sessionGet('columns'); $columns = $this->sessionGet('columns');
$systemLabels = $this->getSystemLabels(); $systemLabels = $this->getSystemLabels();
$fields = array(); $tableFields = array();
$header = array(); $header = array();
/** @var MarkupAdminDataTable $table */ /** @var MarkupAdminDataTable $table */
$table = $this->modules->get('MarkupAdminDataTable'); $table = $modules->get('MarkupAdminDataTable');
$table->setSortable(false); $table->setSortable(false);
$table->setResizable(true); $table->setResizable(true);
$table->setResponsive($this->responsiveTable); $table->setResponsive($this->responsiveTable);
@@ -1256,8 +1277,8 @@ class ProcessPageLister extends Process implements ConfigurableModule {
$subname = ''; $subname = '';
if(strpos($name, '.')) list($name, $subname) = explode('.', $name); if(strpos($name, '.')) list($name, $subname) = explode('.', $name);
$field = $this->template ? $this->template->fieldgroup->getField($name, true) : $this->fields->get($name); $field = $this->template ? $this->template->fieldgroup->getField($name, true) : $fields->get($name);
if(!$field && $this->template) $field = $this->fields->get($name); if(!$field && $this->template) $field = $fields->get($name);
$label = $field ? $field->getLabel() : ''; $label = $field ? $field->getLabel() : '';
if(!$label) $label = isset($systemLabels[$name]) ? $systemLabels[$name] : $name; if(!$label) $label = isset($systemLabels[$name]) ? $systemLabels[$name] : $name;
@@ -1268,7 +1289,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
$label = str_replace($sep1, ' ', $label); $label = str_replace($sep1, ' ', $label);
if($subname) { if($subname) {
$subfield = $this->fields->get($subname); $subfield = $fields->get($subname);
if($subfield) { if($subfield) {
$sublabel = $subfield->getLabel(); $sublabel = $subfield->getLabel();
@@ -1288,7 +1309,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
$label = $this->addLanguageLabel($label, $language); $label = $this->addLanguageLabel($label, $language);
} }
$label = $this->wire('sanitizer')->entities1($label); $label = $sanitizer->entities1($label);
$label = str_replace($sep1, "$sep2<wbr>", $label); $label = str_replace($sep1, "$sep2<wbr>", $label);
if($icon) { if($icon) {
@@ -1304,16 +1325,27 @@ class ProcessPageLister extends Process implements ConfigurableModule {
} else if($subname) { } else if($subname) {
$label = "<strong>" . str_replace($sep2, "$sep2</strong>", $label); $label = "<strong>" . str_replace($sep2, "$sep2</strong>", $label);
} }
$sortKey = $subname ? "$name.$subname" : $name; $thClass = '';
$header[$key] = "$icon$label<b>$sortKey</b>"; if($subname) {
$fields[$name] = $field; $sortKey = "<b>$name.$subname</b>";
if($field && !$this->isSortableCol($field, $subname)) {
$thClass = 'not_sortable';
}
} else {
$sortKey = "<b>$name</b>";
}
$th = "$icon$label$sortKey";
if($thClass) $th = array($th, $thClass);
$header[$key] = $th;
$tableFields[$name] = $field;
} }
$table->headerRow($header); $table->headerRow($header);
foreach($results as $p) { foreach($results as $p) {
$table->row($this->buildListerTableRow($p, $fields, $columns), array( $table->row($this->buildListerTableRow($p, $tableFields, $columns), array(
'attrs' => array('data-pid' => $p->id) 'attrs' => array('data-pid' => $p->id)
)); ));
} }

View File

@@ -39,6 +39,12 @@
// icons // icons
font-size: 14px; font-size: 14px;
} }
&.not_sortable {
cursor: not-allowed;
&:hover {
text-decoration: none;
}
}
} }
th strong { th strong {
// icon + first word of label // icon + first word of label