diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index ac838a7cc..580632118 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -111,13 +111,14 @@ class Items extends Secure_Controller $search = $this->request->getGet('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->sanitizeSortColumn(itemSortColumns(), $this->request->getGet('sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 'items.item_id'); $order = $this->request->getGet('order', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $this->item_lib->set_item_location($this->request->getGet('stock_location')); - $definitionNames = $this->attribute->getDefinitionsByFlags(Attribute::SHOW_IN_ITEMS); $definitionNamesWithTypes = $this->attribute->getDefinitionsByFlags(Attribute::SHOW_IN_ITEMS, true); + $definitionIds = array_keys($definitionNamesWithTypes); + + $sort = $this->sanitizeSortColumn(itemSortColumns($definitionIds), $this->request->getGet('sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 'items.item_id'); $filters = [ 'start_date' => $this->request->getGet('start_date'), @@ -130,7 +131,7 @@ class Items extends Secure_Controller 'search_custom' => false, 'is_deleted' => false, 'temporary' => false, - 'definition_ids' => array_keys($definitionNames) + 'definition_ids' => $definitionIds ]; // Check if any filter is set in the multiselect dropdown diff --git a/app/Helpers/tabular_helper.php b/app/Helpers/tabular_helper.php index 867985e5a..fcc5ec90f 100644 --- a/app/Helpers/tabular_helper.php +++ b/app/Helpers/tabular_helper.php @@ -403,12 +403,16 @@ function item_headers(): array /** * Get all sortable column keys for items table, including dynamic attribute columns. * + * @param array|null $definitionIds Attribute definition IDs to append as sortable columns. + * If null, resolved via a query against SHOW_IN_ITEMS. * @return array Array of column headers in the format sanitizeSortColumn() expects */ -function itemSortColumns(): array +function itemSortColumns(?array $definitionIds = null): array { - $attribute = model(Attribute::class); - $definitionIds = array_keys($attribute->getDefinitionsByFlags($attribute::SHOW_IN_ITEMS)); + if ($definitionIds === null) { + $attribute = model(Attribute::class); + $definitionIds = array_keys($attribute->getDefinitionsByFlags($attribute::SHOW_IN_ITEMS)); + } $headers = item_headers();