> ## Documentation Index
> Fetch the complete documentation index at: https://docs.advancedtables.com/llms.txt
> Use this file to discover all available pages before exploring further.

# User Views

> Allow end-users to save and manage their own custom table configurations including filters, sorting, column order, and grouping.

User Views are views created by your end-users using your application's UI. An end-user chooses the appropriate filters, toggled columns, column order, column sort, table grouping, etc. to build the view they need. Then they use Advanced Tables to save that view so they have easy access to it in the future. Since each user has different needs, this allows for infinite customization within your application. (And less work for developers!)

## Saving the current table configuration into a User View

To save a User View:

1. On your table, apply any combination of filters, toggled columns, sort order, grouping, etc.
2. After customizing your table, click the `+` in the top right corner of the table.
3. Choose a name, icon, and color for the view.
4. Choose if you want the view to be added to your favorite views, made public for other users, or be a global favorite.
5. Save the view

When creating a user view the following configurations will be saved:

* current filters,
* table search query,
* column search queries (if enabled)
* column sort order
* toggled columns
* column order
* grouping

After creation, the View Manager allows a user to sort, edit, replace, or delete a User View.

## User View configurations

Advanced Tables offers multiple ways to customize User Views. Unless specified otherwise, these options can be configured directly on the `AdvancedTablesPlugin` object inside your `PanelProvider`:

```php theme={null}
public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            AdvancedTablesPlugin::make()
                ->userViewsEnabled(false)
        ])
```

### Disable User Views

User Views are enabled by default. However, if you are not going to use User Views, you should disable them to prevent unnecessary database queries:

```php theme={null}
AdvancedTablesPlugin::make()
    ->userViewsEnabled(false)
```

### Configuring the User View model

The `UserView` model is responsable for storing all the configuration settings for each User View. If you need to extend this class, you may pass your custom class to `userView()`:

```php theme={null}
AdvancedTablesPlugin::make()
    ->userView(MyCustomUserView::class)
```

### Configuring the Managed User View class

The `ManagedUserView` model is responsable for managing the visibility and sort order between a `User` and a `UserView`. If you need to extend this class, you may pass your custom class to `managedUserView()`:

```php theme={null}
AdvancedTablesPlugin::make()
    ->managedUserView(myCustomManagedUserView::class)
```

### Disabling the icon picker

You may disable the icon picker in the Save View/Edit View slideOver by passing `false` to the `quickSaveIconSelect()` method:

```php theme={null}
AdvancedTablesPlugin::make()
    ->quickSaveIconSelect(false)
```

You may also use [policies](/v5/configuration/authorization) to configure who can use the icon picker.

### Excluding solid or outline icons

By default the icon picker loads all of heroicons solid and outline icons. You may exclude either solid or outline icons by passing false to either the `quickSaveIncludeOutlineIcons()` or `quickSaveIncludeSolidIcons()` methods:

```php theme={null}
AdvancedTablesPlugin::make()
    ->quickSaveIncludeSolidIcons(false)
```

> Important: Since icons are cached, after updating you will need to clear your cache to see the change with `php artisan cache:clear`.

### Configuring the color picker colors (New)

By default, the color picker will include Filament's [default colors](https://filamentphp.com/docs/3.x/support/colors#customizing-the-default-colors), `primary`, `success`, `info`, `warning`, `danger`, `gray`. To configure the available colors, pass an array of colors to `->quickSaveColors()`:

```php theme={null}
AdvancedTablesPlugin::make()
    ->quickSaveColors([
        'primary',
        'warning',
        'gray',
    ])
```

You may also include any [extra colors you have previously registered in Filament](https://filamentphp.com/docs/3.x/support/colors#registering-extra-colors):

```php theme={null}
AdvancedTablesPlugin::make()
    ->quickSaveColors([
        'primary',
        'success',
        'indigo',
        'pink',
        'zinc',
    ])
```

### Disabling the color picker

You may disable the color picker in the Save View/Edit View slideOver by passing `false` to the `->quickSaveColorPicker()` method:

```php theme={null}
AdvancedTablesPlugin::make()
    ->quickSaveColorPicker(false)
```

You may also use [policies](/v5/configuration/authorization) to configure who can use the color picker.

### Disabling making a User View favorite

By default, when creating/editing a view, users can favorite their views by toggling on `Add to favorites`. Favorite views are added to the [Favorites Bar](/v5/configuration/action-customization#favorites-bar) and appear above the table. You may disable the ability to make a User View favorite by passing `false` to the `->quickSaveMakeFavorite()` method:

```php theme={null}
AdvancedTablesPlugin::make()
    ->quickSaveMakeFavorite(false)
```

You may also use [policies](/v5/configuration/authorization) to configure who can make views favorite.

### Disabling making a User View public

By default, when creating/editing views, users can share their views with other users by toggling on `make public`. Public views will appear in other user's View Manager where they can then be added to their favorites if they wish.

Advanced Tables also has an [approval system](/v5/features/user-views#approving-public-and-global-favorite-user-views) so admins can approve public views before they are visible to other users.

You may disable the ability to make a User View public using the `->quickSaveMakePublic()` method:

```php theme={null}
AdvancedTablesPlugin::make()
    ->quickSaveMakePublic(false)
```

You may also use [policies](/v5/configuration/authorization) to configure who can make views public.

### Enabling making a User View a global favorite

Making a User View a global favorite automatically adds it to every user's Favorites Bar. As this is an action usually reserved for admin users, this functionality is turned off by default. You may enable the ability to make a User View a global public using the `->quickSaveMakeGlobalFavorite()` method:

```php theme={null}
AdvancedTablesPlugin::make()
    ->quickSaveMakeGlobalFavorite()
```

After enabling, you may use [policies](/v5/configuration/authorization) to further configure who can make views global favorites.

Advanced Tables also has an [approval system](/v5/features/user-views#approving-public-and-global-favorite-user-views) so admins can approve global favorite views before they are visible to other users.

### Disabling management of global favorite views

As previously mentioned, when an admin or user creates a global favorite view, that view is added to all user's Favorites Bar. By default, these global views can then be managed (ie. sort and favorite/un-favorite) independently by each user. If you need to disable management of global User View you may do so by passing `false` to the `->globalUserViewsManageable()` method:

```php theme={null}
AdvancedTablesPlugin::make()
    ->globalUserViewsManageable(false)
```

By disabling `globalUserViewsManageable`, global favorites will be not be able to be sorted nor removed from a user's Favorites Bar.

### Configuring new global user view's sort position

When global favorite management is disabled, all global favorites are added *before* any User Views that a user has favorited. However, when global view management is enabled, a user is then free to reorder them, placing global views before, after, or in between their own user-favorited views. Now, when a *new* global view is created by an admin, a decision needs to be made as to whether this new global view should be placed `before` or `after` the user's previously ordered favorite views. By default new global views are positioned `before` a user's favorited views, however this can be configured using the `newGlobalUserViewSortPosition()` method:

```php theme={null}
AdvancedTablesPlugin::make()
    ->newGlobalUserViewSortPosition('after')
```

### Showing/hiding helper text

When creating/editing User Views you may show/hide helper text to help guide your end-users during the process. By default, helper text is only displayed for the Favorite, Public, and Global Favorite toggles.

```php theme={null}
AdvancedTablesPlugin::make()
    ->quickSaveNameHelperText(false)
    ->quickSaveFiltersHelperText(false)
    ->quickSavePublicHelperText(false)
    ->quickSaveFavoriteHelperText(false)
    ->quickSaveGlobalFavoriteHelperText(false)
```

You may configure the wording of each helper text by modifying the [language file](/v5/configuration/additional-configurations#language-files).

### Approving public and global favorite User Views

Advanced Tables includes a simple approval mechanism to allow admins to approve/reject public and global favorites before they are made available to other users.

Advanced Tables uses [Filament's enum](https://filamentphp.com/docs/3.x/support/enums) to define the  `Status` constants:

```php theme={null}
enum Status: string implements HasLabel, HasColor
{
    case Approved = 'approved';
    case Pending = 'pending';
    case Rejected = 'rejected';
```

To use the approval system, first, set the User View's `initialStatus()` to either `Status::Approved`, `Status::Pending`, or `Status::Rejected`. By default, each User View has an initial status of `Status::Pending`:

```php theme={null}
AdvancedTablesPlugin::make()
    ->initialStatus(Archilex\AdvancedTables\Enums\Status::Rejected)
```

Then, set the `minimumStatusForDisplay()` to either `Status::Approved`, `Status::Pending`, or `Status::Rejected`. By default, the minimal status is `Status::Pending`:

```php theme={null}
AdvancedTablesPlugin::make()
    ->minimumStatusForDisplay(Archilex\AdvancedTables\Enums\Status::Approved)
```

When a User View's status is the equal or greater than the `minimumStatusForDisplay()`, it will be displayed to other users.

Advanced Tables default setting of `Pending` for both `Status` and `minimumStatusForDisplay` means that all public and global User Views will automatically be displayed to other users, effectively bypassing the approval system. Changes only need to be made if you would like to enable the approval system.

To update the status of a User View, admin should use the [User Views Resource](/v5/features/user-views-resource).

Of course, Laravel's [Observers](https://laravel.com/docs/10.x/eloquent#observers) can be implemented on the `UserView` model to further expand the approval system with database or email notifications.

### Persisting the active User View to Session

Persisting the active User View to the session allows a user to navigate away from the table and then return to the table with the same view selected. You may enable this by using the `->persistActiveViewInSession()` method:

```php theme={null}
AdvancedTablesPlugin::make()
    ->persistActiveViewInSession()
```
