Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Use aginev/datagrid #295

Open
shemgp opened this issue Sep 14, 2016 · 3 comments
Open

[Feature] Use aginev/datagrid #295

shemgp opened this issue Sep 14, 2016 · 3 comments
Labels

Comments

@shemgp
Copy link
Contributor

shemgp commented Sep 14, 2016

Hello,

I would like to use https://github.com/aginev/datagrid with patches (aginev/datagrid#6) in the generated table.blade.php as it has sorting and filters, etc and would like to have you input on how to go about it. I realize that I probably need to edit generateBladeTableBody() in ViewGenerator.php to make it work I want it also to only be an option and not a replacement. How would I go about it? would you accept an if statement in the generateBladeTableBody() to choose between original and datagrid?

Here's my sample table.blade.php:

<table class="table table-responsive" id="modems-table">
    <thead>
        <th>Serial</th>
        <th>MAC Address</th>
        <th>Modem Type</th>
        <th>Created/Updated by</th>
        <th colspan="3">Action</th>
    </thead>
    <tbody>
    @foreach($modems as $modem)
        <tr>
            <td>{!! $modem->serial !!}</td>
            <td>{!! $modem->mac_address !!}</td>
            <td>{!! $modem->modemType->name !!}</td>
            <td>{!! $modem->user->full_name !!}</td>
            <td>
                {!! Form::open(['route' => ['inventory.modems.destroy', $modem->id], 'method' => 'delete']) !!}
                <div class='btn-group'>
                    <a href="{!! route('inventory.modems.show', [$modem->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
                    <a href="{!! route('inventory.modems.edit', [$modem->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
                    {!! Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}
                </div>
                {!! Form::close() !!}
            </td>
        </tr>
    @endforeach
    </tbody>
</table>

Here's the one converted (similar) to using datagrid

<?php
use PrettyDateTime\PrettyDateTime;

$grid = new \Datagrid($modems, Request::get('f', []));
$grid
    ->setColumn('serial', 'Serial')
    ->setColumn('mac_address', 'MAC Address', [
        'sortable' => true,
        'has_filters' => true,
    ])
    ->setColumn('modemType.name', 'Modem Type', [
        'sortable'    => true,
        'has_filters' => true,
    ])
    ->setColumn('user.full_name', 'Created/Updated by', [
        'sortable'    => true,
        'has_filters' => true,
        'wrapper'=> function ($value, $row) {
            $tooltip = $row->updated_at ? $row->updated_at : $row->created_at;
            $tooltip = PrettyDateTime::parse(new DateTime($tooltip));
            return '<span title="'.$tooltip.'">'.$value.'</span>';
        }
    ])
    // Setup action column
    ->setActionColumn([
        'wrapper' => function ($value, $modem) {
            $out = Form::open(['route' => ['inventory.modems.destroy', $modem->id], 'method' => 'delete']);
            $out .= '<div class="btn-group">';
            $out .= '    <a href="'.route('inventory.modems.show', [$modem->id]).'" class="btn btn-default btn-xs"><i class="glyphicon glyphicon-eye-open"></i></a>';
            $out .= '    <a href="'.route('inventory.modems.edit', [$modem->id]).'" class="btn btn-default btn-xs"><i class="glyphicon glyphicon-edit"></i></a>';
            $out .= Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]);
            $out .= '</div>';
            $out .= Form::close();

            return $out;
        }
    ]);

    echo $grid->show();
?>

Thank you.

@underdpt
Copy link

Hi,

You know you can use datatables?

It doesn't have a per-column filter (only a global search field), but that can be easily achieved (see here)

@shemgp
Copy link
Contributor Author

shemgp commented Sep 15, 2016

Hello,
Yes, but it only works with js enabled. I tried using datatables and it would not show the data.  Probably because of a library problem. Plus, looking at the code, it's hard to customize the columns.  
Hopefully, you would you accept a pull request. I kind of have it working locally with a patched Repository (need to patch to make filters filter using AND) and it'll need to add files to core-templates too.

@shemgp
Copy link
Contributor Author

shemgp commented Sep 16, 2016

Here's the pull request: #296

@ShaileshInfyom ShaileshInfyom changed the title Use aginev/datagrid [Feature] Use aginev/datagrid Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants