PHPackages                             lara-igniter/laraigniter-sortable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lara-igniter/laraigniter-sortable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lara-igniter/laraigniter-sortable
=================================

Sortable behavior package for Laraigniter

v1.2.0(2mo ago)05↓90%MITPHPPHP ^7.4

Since Mar 24Pushed 2mo agoCompare

[ Source](https://github.com/lara-igniter/laraigniter-sortable)[ Packagist](https://packagist.org/packages/lara-igniter/laraigniter-sortable)[ RSS](/packages/lara-igniter-laraigniter-sortable/feed)WikiDiscussions 1.x Synced 3w ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

lara-igniter/laraigniter-sortable
=================================

[](#lara-igniterlaraigniter-sortable)

Column-sortable behavior for the **Laraigniter** framework.
Provides a model trait, a Blade directive, and a config file that work natively with CodeIgniter 3's query builder and the `lara-igniter/framework` glue layer.

---

Package structure (repository root)
-----------------------------------

[](#package-structure-repository-root)

```
laraigniter-sortable/
├── composer.json
├── config/
│   └── sortable.php          ← package defaults (CI $config = [...] format)
└── src/
    ├── SortableServiceProvider.php
    ├── SortableLink.php       ← renders the  sort anchor + icon
    ├── SortableState.php      ← holds the active default sort per request
    └── Traits/
        └── Sortable.php       ← use in any MY_Model subclass

```

---

Installation
------------

[](#installation)

### 1. Install with Composer

[](#1-install-with-composer)

```
composer require lara-igniter/laraigniter-sortable
```

### 2. (Optional) Use a local checkout during development

[](#2-optional-use-a-local-checkout-during-development)

If you are developing the package locally, add a `path` repository in your app's root `composer.json`:

```
"repositories": [
    {
        "type": "path",
        "url": "../laraigniter-sortable",
        "options": { "symlink": true }
    }
],
"require": {
    "lara-igniter/laraigniter-sortable": "*"
}
```

```
composer update lara-igniter/laraigniter-sortable
```

### 3. Register the service provider (only if auto-discovery is disabled)

[](#3-register-the-service-provider-only-if-auto-discovery-is-disabled)

The package declares its provider in `composer.json` under `extra.laraigniter.providers`, so in standard setups no manual registration is needed.

If your project disables package discovery, register it in `config/hooks.php`:

```
$hook = Hooks::autoload([
    'providers' => [
        // ...existing providers...

        /*
         * Package Service Providers...
         */
        Laraigniter\Sortable\SortableServiceProvider::class,
    ],
]);
```

That's it. The provider runs on the `post_controller_constructor` hook, so it is always ready before any controller method or Blade view executes.

---

Configuration
-------------

[](#configuration)

### How config loading works

[](#how-config-loading-works)

The `SortableServiceProvider` uses a `mergeConfigFrom()` method that **prepends** the package root to CodeIgniter's `_config_paths` array.

When `config('sortable.xxx')` is called for the first time:

1. CI's lazy loader finds `vendor/lara-igniter/laraigniter-sortable/config/sortable.php` (or your local path checkout) → loads it as the section `sortable`.
2. If an app-level `config/sortable.php` exists, it is found next and **merged on top** (`array_merge`) — **app values always win**.
3. If no app-level file exists, the package defaults are used as-is, and CI returns `TRUE` without an error.

This mirrors exactly how `loadViewsFrom()` works in `Elegant\Pagination\PaginationServiceProvider`.

### Publishing the config (to override defaults)

[](#publishing-the-config-to-override-defaults)

```
php artisan vendor:publish --tag=sortable
```

This copies `vendor/lara-igniter/laraigniter-sortable/config/sortable.php` → `config/sortable.php`.
Edit the published file — your values will automatically override the package defaults.

### Available options (`config/sortable.php`)

[](#available-options-configsortablephp)

KeyDefaultDescription`columns``alpha / amount / numeric` groupsMaps column names to icon class + sort type`enable_icons``true`Show/hide the sort icon next to the link text`default_icon_set``fa fa-sort`Icon class used for unrecognised column types`default_icon_type``default`Fallback type key for suffix lookup`sortable_icon``fa fa-sort`Icon shown when the column is not currently sorted`clickable_icon``false`When `true` the icon itself is wrapped inside the ```icon_text_separator``''` (empty string)String/HTML placed between the link text and the icon`asc_default_suffix``-asc`Icon suffix for ascending on untyped columns`desc_default_suffix``-desc`Icon suffix for descending on untyped columns`asc_alpha_suffix``-asc`Icon suffix for ascending on alpha columns`desc_alpha_suffix``-desc`Icon suffix for descending on alpha columns`asc_amount_suffix``-asc`Icon suffix for ascending on amount columns`desc_amount_suffix``-desc`Icon suffix for descending on amount columns`asc_numeric_suffix``-asc`Icon suffix for ascending on numeric columns`desc_numeric_suffix``-desc`Icon suffix for descending on numeric columns`anchor_class``null`CSS class on every sort `` — none added when `null``active_anchor_class``null`Extra class added when the column is the active sort`order_anchor_class_prefix``null`Prefix for a dynamic direction class on the active anchor`formatting_function``null`Callable applied to the column title (e.g. `mb_strtoupper`)`title_inside_anchor``false`Use the raw column name as title when none is passed`format_custom_titles``true`Apply `formatting_function` to explicit titles too`inject_title_as``null`Query-string key to inject the formatted title into`default_order``asc`Direction used when no explicit order is provided`default_order_unsorted``asc`Direction used for columns not currently sorted`default_first_column``id`Column used when the model has no `?sort=` param and no explicit default---

Usage
-----

[](#usage)

### 1. Add the trait to your model

[](#1-add-the-trait-to-your-model)

```
