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

Add hidden columns and change export function to suit CRUD architecture #960

Closed
wants to merge 3 commits into from

Conversation

b8ne
Copy link
Contributor

@b8ne b8ne commented Sep 14, 2017

This issue still may be up for discussion.
What ive done here is made the export functionality suit the Backpack CRUD architecture rather than its native Datatables architecture.
The export will now look for columns with a given class rather than those that are visible.
The CRUD setup would be:

$this->crud->addColumn([
    'name' => "Name",
    'type' => 'text',
    'exportable' => true
]);

I have also added a hidden column template, so columns may be included in the export but not visible in the listing.

$this->crud->addColumn([
    'name' => "Name",
    'type' => 'hidden',
    'exportable' => true
]);

@niladam
Copy link
Contributor

niladam commented Sep 14, 2017

I think this looks really good and is a really simple and nice approach. @tabacitu think this will make it into master ? Not really a hard to review PR.. :)

@b8ne
Copy link
Contributor Author

b8ne commented Sep 14, 2017

Thanks @niladam, one thing i did notice this arvo is the column filter button is rendered pretty useless. Ill have a look at it tomorrow, but it may be worth just ditching it as part of this PR? What do you guys think?

@niladam
Copy link
Contributor

niladam commented Sep 14, 2017

Yeah, but the column filter should stay there.

Personally i think providing people with the option to CHOOSE what they want to see is a really strong point in datatables.

I think it makes sense to use a different approach, and not use hidden for the export => false, as this could also allow for integration with the column filters ?

@b8ne
Copy link
Contributor Author

b8ne commented Sep 15, 2017

Updated it now to just use styles to hide hidden cols. Column filter works and 'Actions' are not included in export.

@indra1
Copy link

indra1 commented Sep 15, 2017

Did you test it with ajax tables as well?

@Spodnet
Copy link

Spodnet commented Aug 9, 2018

Just a note this won't work with the ajax code, also having a type hidden doesn't allow you to use the different column types for extracting the data.

The way I implemented it was to set a hidden = true attribute on the column, then in the data tables code I get the array index of all columns that are set hidden = true, and define

@if (count($hidden) > 0)
        "columnDefs" : [
        	{
                "targets" : [{{ implode(',', $hidden) }}],
                "visible" : false
        	}
        ],
@endif

This then hides the columns, allowing the visibility options on data tables to work for export.

@tabacitu tabacitu changed the base branch from master to release-3-5 November 15, 2018 07:50
@tabacitu
Copy link
Member

Totally agree with both @b8ne and @Spodnet here:

  • actions should not be exportable (nobody needs that)
  • we should have a way to hide columns from the table by default
  • we should be able to hide columns other than text (so it’s better to have an option on all column types instead of a hidden column type)

I’m glad to say I’ve just finished this PR #1703 , which fixes all of the above :-)

So I’m going to close this PR - thank you for submitting it though @b8ne - it helped developing a more general solution. The syntax is a little changed, but you’ll notice it’s all there :-)

Cheers!

@tabacitu tabacitu closed this Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants