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

Ajax table view doensn't work with model_function columns #217

Closed
AndreyBobrov opened this issue Nov 2, 2016 · 8 comments
Closed

Ajax table view doensn't work with model_function columns #217

AndreyBobrov opened this issue Nov 2, 2016 · 8 comments

Comments

@AndreyBobrov
Copy link

AndreyBobrov commented Nov 2, 2016

model_function, model_function_attribute columns doesn't use actual db columns, so this causes an issue in search() function in trait AjaxTable:

        $columns = collect($this->crud->columns)
                    ->reject(function ($column, $key) {
                        // the select_multiple columns are not searchable
                        return isset($column['type']) && $column['type'] == 'select_multiple';
                    })
                    ->pluck('name')
                    // add the primary key, otherwise the buttons won't work
                    ->merge($this->crud->model->getKeyName())
                    ->toArray();

        // structure the response in a DataTable-friendly way
        $dataTable = new \LiveControl\EloquentDataTable\DataTable($this->crud->query, $columns);

This code tries to select non-existent fields from entity table. I think that the right thing would be to replace "reject" method with "filter" and list the types of fields out there that use the real database fields (so user defined types also will work) like that:

$columns = collect($this->crud->columns)
            ->filter(function ($column, $key) {
                return isset($column['type']) && in_array($column['type'], [
                    'array',
                    'array_count',
                    'boolean',
                    'check',
                    'multidimensional_array',
                    'radio',
                    'text',
                    'select',
                    'video'
                ]);
            })
            ->pluck('name')
            // add the primary key, otherwise the buttons won't work
            ->merge($this->crud->model->getKeyName())
            ->toArray();
@tabacitu
Copy link
Member

tabacitu commented Nov 9, 2016

Hi @AndreyBobrov , just saw your issue, sorry, I don't know how it slipped through.

Hmm... I'm afraid replacing "reject" with "filter" would prevent people from using their own custom columns in the search, so we can't do that. But I will place "model_function" and "model_function_attribute" in the "reject" for now, that should at least prevent errors, right?

I'm planning a complete rewrite of the search() method, so that it WILL allow 1-n and n-n searches, model_function and model_attribute_function, but... I think it will take some time to launch it.

Thanks, cheers!

@indra1
Copy link

indra1 commented Nov 11, 2016

@AndreyBobrov Similar issue #190. I bypassed it by overwriting the Ajax table and adding the model_function in the reject list. Another potential quick fix is to change the way you add model_function in a column like this:
$this->crud->addColumn(
[
'type' => 'model_function',
'label' => 'your label',
'function_name' => 'yourFunction',
'name' => 'name_of_the_column_you_use_in_yourFunction'
]);

@OwenMelbz
Copy link
Contributor

I'm just closing this up as there is a duplicate over at #190 and @tabacitu has confirmed he'll be working on it, has been listed #285

@adbmdp
Copy link
Contributor

adbmdp commented Jan 25, 2017

Any news of when this bug will be resolves?

@indra1
Copy link

indra1 commented Feb 22, 2017

@adbmdp yeah, I think I fixed it, but i'm still testing. I will let you know when we're done.
You can checkout my solution here: https://github.com/indra1/CRUD (check the AjaxTrait.php file)

@mdevo
Copy link

mdevo commented Feb 24, 2017

He rewrite entire search function and add few functions in ReadTrait:
https://github.com/indra1/CRUD/commit/51fea353523d4b3845ae6e6997f7fbeda020f43f

@tabacitu
Copy link
Member

Hi @indra1 ,

Have you had the time to test it out, is it OK from your perspective?

Thanks, cheers!

@indra1
Copy link

indra1 commented Mar 8, 2017

@mdevo he is a she. And yes, I removed a library and I added some functions
@tabacitu it works, but I would like to test it for two more days. Sorry for the delay, I was caught up in something else. I also want to try to change the search function to allow it to sort by relations as well.
Edit: found a bug, and fixed it. I have the package loaded in a project now and besides that bug all seams to be well.

Do you guys have any proposals for that?

Edit: some people were saying it's kind of slow so i'd like to look into that as well. Please let me know your thoughts

This was referenced Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants