question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ajax table view doensn't work with model_function columns

See original GitHub issue

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();

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
indra1commented, 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)

0reactions
indra1commented, Mar 9, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Table functions doesn't work when using ajax - Stack Overflow
And I created a page and the fetch function works but when it's in the table, the table functions doesn't work. At the...
Read more >
Unable to get columnDefs.render to work on columns coming ...
In order to dynamically create the DataTables table I have piggybacked the DataTable init on the return from the "get columns" AJAX request....
Read more >
Beautiful Interactive Tables for your Flask Templates
In this article I'm going to show you how to integrate the dataTables.js library in your templates, which will allow you to create...
Read more >
django-ajax-datatable - PyPI
django-ajax-datatable is a Django app (previously named morlandi/django-datatables-view) which provides advanced integration for a Django project with the ...
Read more >
DataTables.js for Django. Python Classes to ... - Medium
DataTables.js for Django. Python Classes to Implement AJAX Data Table in Django. Hi. In this text, I am not going to write everything...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found