Datagrid add column before and after event added
This commit is contained in:
parent
6c03f824ec
commit
7d7cda1f73
|
|
@ -28,6 +28,8 @@ class AttributeDataGrid extends DataGrid
|
|||
|
||||
public function addColumns()
|
||||
{
|
||||
$this->setInvoker($this);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'id',
|
||||
'label' => trans('admin::app.datagrid.id'),
|
||||
|
|
@ -64,19 +66,19 @@ class AttributeDataGrid extends DataGrid
|
|||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'is_required',
|
||||
'label' => trans('admin::app.datagrid.required'),
|
||||
'type' => 'boolean',
|
||||
'sortable' => true,
|
||||
'searchable' => false,
|
||||
'wrapper' => function($value) {
|
||||
if ($value->is_required == 1)
|
||||
return 'True';
|
||||
else
|
||||
return 'False';
|
||||
}
|
||||
]);
|
||||
// $this->addColumn([
|
||||
// 'index' => 'is_required',
|
||||
// 'label' => trans('admin::app.datagrid.required'),
|
||||
// 'type' => 'boolean',
|
||||
// 'sortable' => true,
|
||||
// 'searchable' => false,
|
||||
// 'wrapper' => function($value) {
|
||||
// if ($value->is_required == 1)
|
||||
// return 'True';
|
||||
// else
|
||||
// return 'False';
|
||||
// }
|
||||
// ]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'is_unique',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Webkul\Product\Commands;
|
||||
|
||||
use Webkul\Product\Repositories\ProductRepository as Product;
|
||||
|
||||
class DemoProducts
|
||||
{
|
||||
/**
|
||||
* Holds ProductRepository instance
|
||||
*/
|
||||
protected $product;
|
||||
|
||||
public function __construct(Product $product)
|
||||
{
|
||||
$this->product = $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* To call the seeder and provide the demo data generators parameters
|
||||
*/
|
||||
public function callGenerator()
|
||||
{
|
||||
|
||||
$result = $this->productSeeder();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Webkul\Ui\DataGrid;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Event;
|
||||
|
||||
/**
|
||||
* DataGrid class
|
||||
|
|
@ -12,22 +12,87 @@ use Illuminate\Http\Request;
|
|||
*/
|
||||
abstract class DataGrid
|
||||
{
|
||||
/**
|
||||
* set index columns, ex: id.
|
||||
*/
|
||||
protected $index = null;
|
||||
|
||||
/**
|
||||
* To know the class of datagrid calling parent methods, to be set by the extending class.
|
||||
*/
|
||||
protected $invoker = null;
|
||||
|
||||
/**
|
||||
* Default sort order of datagrid
|
||||
*/
|
||||
protected $sortOrder = 'asc';
|
||||
|
||||
/**
|
||||
* Situation handling property when working with custom columns in datagrid, helps abstaining
|
||||
* aliases on custom column.
|
||||
*/
|
||||
protected $enableFilterMap = false;
|
||||
|
||||
/**
|
||||
* This is array where aliases and custom column's name are passed
|
||||
*/
|
||||
protected $filterMap = [];
|
||||
|
||||
/**
|
||||
* array to hold all the columns which will be displayed on frontend.
|
||||
*/
|
||||
protected $columns = [];
|
||||
|
||||
protected $completeColumnDetails = [];
|
||||
|
||||
/**
|
||||
* Hold query builder instance of the query prepared by executing datagrid
|
||||
* class method setQueryBuilder
|
||||
*/
|
||||
protected $queryBuilder = [];
|
||||
|
||||
/**
|
||||
* Final result of the datagrid program that is collection object.
|
||||
*/
|
||||
protected $collection = [];
|
||||
|
||||
/**
|
||||
* Set of handly click tools which you could be using for various operations.
|
||||
* ex: dyanmic and static redirects, deleting, etc.
|
||||
*/
|
||||
protected $actions = [];
|
||||
|
||||
/**
|
||||
* Works on selection of values index column as comma separated list as response
|
||||
* to your endpoint set as route.
|
||||
*/
|
||||
protected $massActions = [];
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Parsed value of the url parameters
|
||||
*/
|
||||
protected $parse;
|
||||
|
||||
/**
|
||||
* To show mass action or not.
|
||||
*/
|
||||
protected $enableMassAction = false;
|
||||
|
||||
/**
|
||||
* To enable actions or not.
|
||||
*/
|
||||
protected $enableAction = false;
|
||||
|
||||
/**
|
||||
* paginate the collection or not
|
||||
*/
|
||||
protected $paginate = true;
|
||||
|
||||
/**
|
||||
* If paginated then value of pagination.
|
||||
*/
|
||||
protected $itemsPerPage = 15;
|
||||
|
||||
protected $operators = [
|
||||
'eq' => "=",
|
||||
'lt' => "<",
|
||||
|
|
@ -105,9 +170,13 @@ abstract class DataGrid
|
|||
|
||||
public function addColumn($column)
|
||||
{
|
||||
$this->fireEvent('before.add.column.'.$column['index']);
|
||||
|
||||
array_push($this->columns, $column);
|
||||
|
||||
$this->setCompleteColumnDetails($column);
|
||||
|
||||
$this->fireEvent('after.add.column.'.$column['index']);
|
||||
}
|
||||
|
||||
public function setCompleteColumnDetails($column)
|
||||
|
|
@ -306,12 +375,34 @@ abstract class DataGrid
|
|||
return $collection;
|
||||
}
|
||||
|
||||
protected function fireEvent($name)
|
||||
{
|
||||
$className = get_class($this->invoker);
|
||||
|
||||
$className = last(explode("\\", $className));
|
||||
|
||||
$className = strtolower($className);
|
||||
|
||||
$eventName = $className.'.'.$name;
|
||||
|
||||
Event::fire($eventName, $this->invoker);
|
||||
}
|
||||
|
||||
public function prepareMassActions() {
|
||||
}
|
||||
|
||||
public function prepareActions() {
|
||||
}
|
||||
|
||||
public function setInvoker($class)
|
||||
{
|
||||
$this->invoker = $class;
|
||||
|
||||
// $this->invoker = last(explode("\\", $class));
|
||||
|
||||
// $this->invoker = strtolower($this->invoker);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->addColumns();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
Event::listen('attributedatagrid.before.add.column.id', function($dataGridInstance) {
|
||||
$data = [
|
||||
'index' => 'is_required',
|
||||
'label' => 'trans',
|
||||
'type' => 'boolean',
|
||||
'sortable' => true,
|
||||
'searchable' => false,
|
||||
'wrapper' => function ($value) {
|
||||
if ($value->is_required == 1)
|
||||
return 'True';
|
||||
else
|
||||
return 'False';
|
||||
}
|
||||
];
|
||||
|
||||
$dataGridInstance->addColumn($data);
|
||||
});
|
||||
Loading…
Reference in New Issue