Replies: 1 comment
-
Hi @LaMance22, I am using PowerGrid Demo repository for the following example: I have added two columns: First one with the formatted date containing HTML and one "clean", just the formatted date. public function addColumns(): PowerGridEloquent
{
return PowerGrid::eloquent()
->addColumn('id')
//...
->addColumn('produced_at_formatted', function (Dish $dish) {
return '<b>' . Carbon::parse($dish->produced_at)->format('d/m/Y') . '</b>';
})
->addColumn('produced_at_clean', function (Dish $dish) {
return Carbon::parse($dish->produced_at)->format('d/m/Y');
}); Next, I set Then, /**
* PowerGrid Columns.
*
* @return array<int, Column>
*/
public function columns(): array
{
return [
//..
Column::add()
->title(__('Production without HTML'))
->field('produced_at_clean')
->hidden()
->visibleInExport(true),
Column::add()
->title(__('Production date'))
->field('produced_at_formatted')
->makeInputDatePicker('produced_at')
->visibleInExport(false)
]; This results in the column with HTML being displayed on the screen and the clean column to be hidden on the screen... And the opposite in the Excel file... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, thanks for this project ;). Please give me a suggestion. Can I exclude HTML when exporting columns?
I mark expiring date in red color. Its my code:
addColumn
->addColumn('date_expire_formatted', function (Training $model) { $date_expire= $model->date_expire? Carbon::parse($model->date_expire)->format('d/m/Y') : NULL; if ( $model->date_expire< date('Y-m-d') ) { return '<span class="text-gray-300">'.$date_expire.'</span>'; } elseif ( $model->date_expire<= date('Y-m-d', strtotime('+ 10 days')) ) { return '<span class="text-red-500 font-bold">'.$date_expire.'</span>'; } else { return $date_expire; } })
Column::make (date_expire is column name in database)
Column::make(__('Date expire'), 'date_expire_formatted', 'date_expire') ->searchable() ->sortable(),
In excel:
Beta Was this translation helpful? Give feedback.
All reactions