Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customize columns to export #714

Closed
dj-fiorex opened this issue Jun 1, 2017 · 8 comments
Closed

customize columns to export #714

dj-fiorex opened this issue Jun 1, 2017 · 8 comments

Comments

@dj-fiorex
Copy link

Hi all, first of all thanks for this magic package :) i want to know if i can customize the action of the button inserted in datatable via $this->crud->enableExportButton(), for example i don't want to print the action column in the pdf. How can i archieve this?
Thanks!

@AbbyJanke
Copy link
Contributor

AbbyJanke commented Jun 1, 2017

Hello @dj-fiorex the Export functionality as actually handled by DataTables. Looking at the code for the view it is exporting any tables that are "visible."

              exportOptions: {
              columns: [':visible']
              }

What you are probably going to have to do is overwrite that view file and change it to a custom attribute that you set for each column within your controller.

The file is list.blade.php line 166. My suggestion is add a class or custom attribute to called "exportable" and just not add it to the actions column.

Sorry i cannot give you an example as I am on the phone currently.

@dj-fiorex
Copy link
Author

first of all thanks for the reply :) i looked at the code but i don't understand how the :visible selector act, i tried to add a custom class to my columns in the CrudController

$this->crud->addColumn([
       // 1-n relationship
       'label' => "MSRP", // Table column heading
       'type' => "select",
       'name' => 'id', // the column that contains the ID of that connected entity;
       'entity' => 'price', // the method that defines the relationship in your Model
       'attribute' => "msrp", // foreign key attribute that is shown to user
       'model' => "App\Models\ProductPrice", // foreign key model
       'wrapperAttributes' => [
          'class' => 'toPdf'
        ]
     ]);

and then change :visible with :toPdf but seems not to work :(
Can you help me?
Thanks

@AbbyJanke
Copy link
Contributor

Hi, so the :visible Selector is checking for any columns/rows that are not hidden meaning you can see them in the web browser. I believe if you change jt to .toPdf It will work.

There is more documentation on how DatsTables selects columns here: https://datatables.net/reference/type/column-selector

@dj-fiorex
Copy link
Author

dj-fiorex commented Jun 1, 2017

i have read the documentation about datatable, i also try to modify my select.blade.php to add a class on td element

<?php
echo '<td class="toPdf">';

		if ($entry->{$column['entity']}) {
	    	echo $entry->{$column['entity']}->{$column['attribute']};
	    }

echo '</td>';
?>

and then add a 'class' => 'toPdf', in my columns in crud controller but didn't work :(
in my opinion the DataTables column selector act on th element so i need to add the class to the th element, maybe!

!!UPDATE!!
Just test it! i change list.blade.php from :visible to .sorting just to test if i thought well and it works, so now i need to know how to add a class on the th element :)

@dj-fiorex
Copy link
Author

Ok i found how to do it!
Modify list.blade.php line 47

<th class="{{ $column['class'] }}">{{ $column['label'] }}</th>

and line 166

columns: ['.exportable']

finally add to your columns definition in crudcontroller

$this->crud->addColumn([
       [ .... ]
        'class' => 'exportable'
      ]); 

Thanks for the help!

@dj-fiorex dj-fiorex changed the title customize pdf download customize columns to export Jun 1, 2017
@AbbyJanke
Copy link
Contributor

Glad you got it working. Sorry i couldnt help more have been at work the entire time and only have my phone.

@dj-fiorex
Copy link
Author

don't worry! you give me the input to start coding ahahah.
But there are any news about 1-1 relationship? because i try this solution but i can't figure out how to do this

@niladam
Copy link
Contributor

niladam commented Sep 14, 2017

I think adding a reference to #960 in here should also help future users that need this..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants