-
-
Notifications
You must be signed in to change notification settings - Fork 858
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
Filter/search/order for nested relations #922
Comments
I took am having the same issue. I have the following code protected function dataTables($request, $runs) {
//Create DataTables object
$runs = RunAvailability::query();
$runs->with('foodprofile', 'foodprofileavailability', 'foodprofile.user');
$dt = Datatables::of($runs);
//Add Columns
$dt->addColumn('organization', function ($row) {
return $row->foodProfile->user->organization;
});
$dt->addColumn('date', function ($row) {
return date('m/d/Y', strtotime($row->date));
});
$dt->addColumn('day', function ($row) {
return date('l', strtotime($row->date));
});
$dt->addColumn('start_time', function ($row) {
return date('g:ia', strtotime($row->foodProfileAvailability->start_time));
});
$dt->addColumn('end_time', function ($row) {
return date('g:ia', strtotime($row->foodProfileAvailability->end_time));
});
$dt->addColumn('food_size_id', function ($row) {
return $row->foodProfile->foodSizes()->first()->name;
});
$dt->addColumn('food_types', function ($row) {
$foodTypes = $row->foodProfile->foodTypes()->pluck('name');
return implode('<br>' , $foodTypes->toArray());
});
$dt->addColumn('city', function ($row) {
return $row->foodProfile->user->city;
});
$dt->addColumn('state', function ($row) {
return $row->foodProfile->user->state;
});
$dt->addColumn('zipcode', function ($row) {
return $row->foodProfile->user->zipcode;
});
return $dt->make(true);
} With the following JS $(function () {
var $filterTag = $('.filter-tag');
var dTable = $('#userList').DataTable({
responsive: true,
processing: true,
serverSide: true,
ajax: {
url: '{!! route('ajax-staff-runs-donor') !!}',
data: function (d) {
var tag = $filterTag.val();
if (tag) {
d.tag = tag;
}
}
},
pageLength: 25,
order: [[1, "asc"]],
columns: [
{data: "organization", name: "foodprofile.user.organization"},
{data: "date"},
{data: "day"},
{data: "start_time"},
{data: "end_time"},
{data: "food_size_id"},
{data: "food_types"},
{data: "city"},
{data: "state"},
{data: "zipcode"},
{
data: null,
render: function (data, type, row) {
return '<a href="https://app.foodrescue.us/runs/' + data.id + '/receiver" class="btn btn-success btn-sm">Select Donor</a>';
},
name: 'actions', orderable: false, searchable: false
}
]
});
$filterTag.on('change', function (e) {
dTable.draw();
});
}); When I try to Order by or Search by Organization, I get |
This is happening for me because we are adding a Global scope which adds 2 new columns. I.E.
If I remove the global scope it works fine, we would prefer NOT to have to remove the global scope though. Any suggestions? |
@Luis-Goncalves-Searchprof nested relations is working but still have some issues. I am currently working on fixing ordering along with this PR #850. ATM, I must say that nested eager loading support is not yet stable. Thanks! |
I have the same issue, I'm currently using datatabels 7.0 and Laravel 5.4 Here is my code Controller
Javascript
Can anyone help me and notice my problem? |
@Yarandi see #1137 (comment) for a possible fix on v7. Thanks! |
@yajra Sorry i saw this is the active issue. So is this still WIP ? |
I found a work around about the nested relationship problem which occurs when tables have a pivot table. I don't know if it's the best option but at the Note:
|
Hi,
Back to the subject of issue #696 I'm wondering if the nested relations are already working. I'm using L5.3 and the latest version of the package and the search and ordering aren't working well.
Controller method:
JS code:
Inside the datatable construction i have the columns defined like this:
The database is populated well. The only fields where the search and order dont work well are the "country" and "district".
I noticed that in the documentation you mentioned them:
«Same strategy goes for nested relationships but do NOTE that ordering is not yet fully tested on nested relationships.»
So, is the nested relationships working well or? :)
Thanks
The text was updated successfully, but these errors were encountered: