Replace data when exporting to csv or xlsx #1519
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You can create two fields, one containing the raw data and the other containing the formatted HTML link. Let's call them Then, you then hide the column for In addiction, you can make the column for For example: Fields: use PowerComponents\LivewirePowerGrid\Exportable;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
final class MyPowergridTable extends PowerGridComponent
{
use WithExport;
//....
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('raw_contact_data', function (Dish $model) {
return $model->name;
})
->add('html_contact_data', function (Dish $model) {
return '<a href="https://www.foobar.com/?q=' . e($model->name) . '"> Click for: '. e($model->name) .'</a>';
});
} Columns: use PowerComponents\LivewirePowerGrid\Exportable;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
final class MyPowergridTable extends PowerGridComponent
{
use WithExport;
//....
public function columns(): array
{
return [
Column::make('ID', 'id')
->searchable()
->visibleInExport(false)
->sortable(),
Column::make('Contact', 'html_contact_data')
->visibleInExport(false)
->sortable(),
Column::make('Contact', 'raw_contact_data', 'name') //added "name" db field for searching"
->searchable()
->sortable()
->visibleInExport(true)
->hidden(true),
Column::make('Created At', 'created_at_formatted'),
];
}
} The code above will produce a table containing an HTML link: and an exported file containing the only name : |
Beta Was this translation helpful? Give feedback.
-
I still have a question related to Columns. When you have Can I use my model's relationship db field as the 3rd argument instead of the model's field, like: Or do I really have to use 'joins' instead (not to "practical" when you have a lot of fields)? |
Beta Was this translation helpful? Give feedback.
You can create two fields, one containing the raw data and the other containing the formatted HTML link. Let's call them
raw_contact_data
andhtml_contact_data
.Then, you then hide the column for
raw_contact_data
from table view and make it visible for exporting.In addiction, you can make the column for
html_contact_data
visible for exporting and hidden in the table view.For example:
Fields: