|
7 | 7 | The following items have been deprecated in this release:
|
8 | 8 |
|
9 | 9 | * Using `dynamicProperties` in Button macros.
|
10 |
| -* Remove support for `openspout/openspout` v3. |
11 |
| -* Remove `Cache::make()->forever()` method. |
12 |
| -* Cache `rememberForever` via config `cache_data` key. |
13 |
| -* Remove `Button::make()->method()` method. |
14 |
| -* Remove `Button::make()->target()` method (now in route method). |
15 |
| -* Remove `Button::make()->bladeComponent()` available only for `actionRules()`. |
16 |
| -* Remove `Button::make()->render()` You can work around this by using `bladeComponent` in `actionRules()` method. |
17 |
| - |
| 10 | +* Drop support for `openspout/openspout` v3. |
| 11 | +* Removed `Cache::make()->forever()` method. |
| 12 | +* Removed Cache `rememberForever()` via config `cache_data` key. |
| 13 | +* Removed from `Button::make()->method()` method. |
| 14 | +* Removed `Button::make()->target()` method (now in route method). |
| 15 | +* Removed `Button::make()->bladeComponent()` method available only for `actionRules()`. |
| 16 | +* Removed `Button::make()->render()` method You can work around this by using `bladeComponent` in `actionRules()` method. |
| 17 | +* Removed `tom-select.css` from dist. Use native CSS instead of PowerGrid dist path |
18 | 18 | ---
|
19 | 19 |
|
20 | 20 | ### New Properties
|
@@ -43,7 +43,7 @@ The following items have been deprecated in this release:
|
43 | 43 |
|
44 | 44 | ### Improves & Features
|
45 | 45 |
|
46 |
| -**Refactored Actions Rendering** |
| 46 | +### ✨ Javascript Actions Rendering |
47 | 47 |
|
48 | 48 | ::: info
|
49 | 49 | * Action rendering has been refactored for better performance and flexibility.
|
@@ -103,3 +103,85 @@ So, our setup will look like this:
|
103 | 103 | | allowed | Only the icons defined here will be processed. If empty, all will be loaded |
|
104 | 104 | | attributes | attributes that will be added by default to the SVG |
|
105 | 105 |
|
| 106 | +### ✨ Column Macros |
| 107 | + |
| 108 | +* If you need to add different query logic when searching for example, you can create a new macro (let's assume `searchableDateFormat`): |
| 109 | + |
| 110 | +`AppServiceProvider`, boot method. |
| 111 | +```php |
| 112 | +Column::macro('searchableDateFormat', function () { |
| 113 | + $this->rawQueries[] = [ |
| 114 | + 'method' => 'orWhereRaw', |
| 115 | + 'sql' => 'DATE_FORMAT('.$this->dataField.', "%d/%m/%Y") like ?', |
| 116 | + 'bindings' => ['%{search}%'], |
| 117 | + 'enabled' => function (PowerGridComponent $component) { |
| 118 | + return filled($component->search); |
| 119 | + }, |
| 120 | + ]; |
| 121 | + |
| 122 | + return $this; |
| 123 | +}); |
| 124 | +``` |
| 125 | + |
| 126 | +Now, in any PowerGrid table component: |
| 127 | +```php |
| 128 | + Column::make('Created At', 'created_at') |
| 129 | + ->searchableDateFormat(), |
| 130 | +``` |
| 131 | + |
| 132 | +### Row Template |
| 133 | + |
| 134 | +If you want to customize a record in the table without using Blade's processing, you can use the rowTemplate() method. This approach prevents the unnecessary creation of Blade components for the same field across different rows by leveraging JavaScript instead. |
| 135 | + |
| 136 | +**Consider the following example:** |
| 137 | + |
| 138 | +::: info |
| 139 | +For each rendered row in the 'name' field, a view will be created in PHP during the rendering process: |
| 140 | +::: |
| 141 | + |
| 142 | +```php |
| 143 | +public function fields(): PowerGridFields |
| 144 | +{ |
| 145 | + return PowerGrid::fields() |
| 146 | + ->add('id') |
| 147 | + ->add('name', function ($row) { |
| 148 | + return \Blade::render(<<<blade |
| 149 | + <div id="custom-\$id" class="bg-red-100 py-1 rounded px-3">\$name</div> |
| 150 | + blade, [ |
| 151 | + 'id' => $row->id, |
| 152 | + 'name' => $row->name, |
| 153 | + ]); |
| 154 | + }) |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +We can simplify this by using JavaScript to handle the rendering, as shown below: |
| 159 | + |
| 160 | +```php{5-11,15-20} |
| 161 | + public function fields(): PowerGridFields |
| 162 | +{ |
| 163 | + return PowerGrid::fields() |
| 164 | + ->add('id') |
| 165 | + ->add('name', function ($row) { |
| 166 | + return [ |
| 167 | + 'template-name' => [ |
| 168 | + 'id' => $row->id, |
| 169 | + 'name' => $row->name, |
| 170 | + ], |
| 171 | + ]; |
| 172 | + }); |
| 173 | +} |
| 174 | +
|
| 175 | +public function rowTemplates(): array |
| 176 | +{ |
| 177 | + return [ |
| 178 | + 'template-name' => '<div id="custom-{{ id }}" class="bg-red-100 py-1 rounded px-3">{{ name }}</div>', |
| 179 | + ]; |
| 180 | +} |
| 181 | +``` |
| 182 | + |
| 183 | +In this setup, we instruct PowerGrid to look for 'template-name' and replace the HTML with the corresponding template during rendering. |
| 184 | +By doing so, the layout and styling are managed by JavaScript, which dynamically populates the fields with the appropriate data for each row. |
| 185 | + |
| 186 | +This approach reduces the overhead associated with generating Blade views for each row, leading to improved performance and easier maintenance, especially when dealing with large datasets. |
| 187 | +Instead of repeatedly rendering Blade components, the JavaScript-based solution efficiently handles the customization directly in the browser, making your application more responsive and streamlined. |
0 commit comments