Package Data | |
---|---|
Maintainer Username: | webmachine |
Maintainer Contact: | contacto@webmachine.cl (WebMachine) |
Package Create Date: | 2017-03-16 |
Package Last Update: | 2022-04-01 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:09:49 |
Package Statistics | |
---|---|
Total Downloads: | 376 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 4 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Via Composer
$ composer require webmachine/jqgrid
Next, you must install the service provider and facade alias:
// config/app.php
'providers' => [
...
Webmachine\Jqgrid\JqgridServiceProvider::class,
];
...
'aliases' => [
...
'Jqgrid' => Webmachine\Jqgrid\JqgridFacade::class,
];
Publish
$ php artisan vendor:publish --provider="Webmachine\Jqgrid\JqgridServiceProvider"
In your Controller
...
use Webmachine\Jqgrid\JqgridFacade as Jqgrid;
class FooController extends Controller {
/**
* @see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options ColModel API.
*/
const jqgrid_colmodel = [
[
'label' => 'Id',
'name' => 'id',
'hidden' => true
],
[
'label' => 'Number',
'name' => 'number',
'searchoptions' => [
'sopt' => ['bw']
]
],
[
'label' => 'Name',
'name' => 'name',
],
[
'label' => 'Provider',
'name' => 'provider.name', // relation.fieldname
'relation' => 'FooModel.provider' // ModelName.relation (this relation must exist in your model)
]
];
...
public function index() {
...
Jqgrid::add_js_colmodel('foo_table', self::jqgrid_colmodel); // add colmodel columns to render in view
return view('foo.index');
...
}
...
/**
* Generate json response for jqgrid
* @return string
*/
public function datagrid() {
Jqgrid::init('foo_table', self::jqgrid_colmodel, self::jqgrid_format());
Jqgrid::get_query()->whereIn('user_id', auth()->user()->id); // add extra query conditions
return Jqgrid::datagrid();
}
...
/**
* Return closure function to format jqgrid columns (optional)
* @return function
*/
private static function jqgrid_format() {
return function ($column, $value) {
$result = $value;
if ($column == 'name') {
$result = ucfirst($value);
}
return $result;
};
}
}
In your view javascript
// foo/index.blade.php
...
<!-- Load Jqgrid scripts in your scripts section -->
{!! Jqgrid::scripts() !!}
...
$('#jqgrid').jqGrid({
url: '{{ url("foo/datagrid") }}',
colModel: {!! Jqgrid::js_colmodel() !!}
...
});
The MIT License (MIT). Please see License File for more information.