Coder Social home page Coder Social logo

yaserzizo / nova-mega-filter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dcasia/nova-mega-filter

0.0 1.0 0.0 278 KB

Allows you to control the columns and filters shown on any Nova resource index

License: MIT License

JavaScript 3.97% Vue 63.67% PHP 32.36%

nova-mega-filter's Introduction

Nova Mega Filter

Latest Version on Packagist Total Downloads License

This package allows you to control the columns and filters shown on your nova resources.

Installation

You can install the package via composer:

composer require digital-creative/nova-mega-filter

Basic Usage

Basic demo showing the power of this field:

use DigitalCreative\MegaFilter\MegaFilter;
use DigitalCreative\MegaFilter\HasMegaFilterTrait;

class ExampleNovaResource extends Resource {

    use HasMegaFilterTrait; // Important!!

    public function cards(Request $request)
    {
        return [
            MegaFilter::make([
                'filters' => [
                    new DateOfBirthFilter(),
                    new UserTypeFilter()
                ],
                'columns' => [
                    Column::make('Customer Name', 'name')->addFilter(new ActiveFilter()),
                    Column::make('Assets'),
                    Column::make('Payments')
                ]
            ])
        ];
    }

}

Columns

Columns reflects every column that is normally shown on your table resource, however you are free to give your user the ability to toggle it on/off:

Columns in Action

use DigitalCreative\MegaFilter\Column;
use DigitalCreative\MegaFilter\MegaFilter;

MegaFilter::make([
    'columns' => [
        Column::make($label),
        Column::make($label, $attribute),
        Column::make($label, $attribute, $filters),
        new Column($label, $attribute, $filters),
    ],
])

You can add additional filters that only appears when the desired column is enabled:

MegaFilter::make([
    'columns' => [
        Column::make('Gender')->addFilter(new GenderFilter())
    ],
])

Columns in Action

If you want to have filters that are always shown, use the 'filters' option bellow

You can also define columns that can not be toggled by the user and will be always present on the table resource:

MegaFilter::make([
    'columns' => [
        Column::make('Name')->permanent()
    ],
])

When using ->permanent() every filter that the column may define will be also present

Filters

The filters key accepts an array of any instance of the default Nova filter class or third party.

MegaFilter::make([
    'filters' => [
       new BirthdayFilter(),
       new UserTypeFilter(),
       new GenderFilter(),
    ],
])

Actions

Actions will use the same Nova action mechanism

MegaFilter::make([
    'actions' => [
       new ExportClientAsExcell(),
    ],
])

Columns in Action

If you have multiple actions defined, a dropdown will be shown:

Columns in Action

The columns selected will also be given to your action, you can access them directly from the request:

public function handle(ActionFields $fields, Collection $models)
{

    $columns = json_decode(request()->input('columns'));

    dd($columns);

}

Settings

The settings key is optional as it comes with some good defaults, but feel free to override it to suit your needs.

MegaFilter::make([
    'settings' => [

        /**
         * Tailwind width classes: w-full w-1/2 w-1/3 w-1/4 etc.
         */
        'columnsWidth' => 'w-1/4',
        'filtersWidth' => 'w-1/2',
        
        /**
         * The default state of the main toggle buttons
         */
        'columnsActive' => false,
        'filtersActive' => true,
        'actionsActive' => true,
        
        /**
         * Labels
         */
        'headerLabel' => 'Menu',
        'columnsLabel' => 'Columns',
        'filtersLabel' => 'Filters',
        'actionsLabel' => 'Actions',
        'columnsSectionTitle' => 'Additional Columns',
        'filtersSectionTitle' => 'Filters',
        'actionsSectionTitle' => 'Actions',
        'columnsResetLinkTitle' => 'Reset Columns',
        'filtersResetLinkTitle' => 'Reset Filters',

    ],
])

License

The MIT License (MIT). Please see License File for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.