@yajra
JQuery code :
<script>
var otable;
$(document).ready(function () {
$('#opacitylow').css({'opacity': 0.5});
$('.loader').css({'opacity': 2.0});
overlay = $('<div></div>').prependTo('body').attr('id', 'overlay');
otable = $('#project-list').DataTable({
processing: true,
serverSide: true,
ajax: '/getData',
columns: [
{data: 'project_view_id', name: 'project_view_id'},
{data: 'project_name.name', name: 'project_name.name'},
{data: 'client.name', name: 'client.name'},
{data: 'client_country.name', name: 'client_country.name'},
{data: 'account_mgr', name: 'account_mgr'},
{data: 'project_mgr', name: 'project_mgr'},
{data: 'project_coordinator', name: 'project_coordinator'},

{data: 'start_date', name: 'start_date'},
{data: 'consultant_count', name: 'consultant_count'},
{data: 'status', name: 'status'}
],
"columnDefs": [
{
"targets": [9],
"visible": false
}
],
fnInitComplete: function () {
$('#opacitylow').css({'opacity': 2.0});
$('.loader').css({'opacity': 0.5});
overlay.remove();
}
});
$('#listing_data').delegate('#listing_status', 'change', function () {
otable.columns(9).search(this.value).draw();
});
});
</script>
On reload page, all is working fine but when i try to search any value then getting a error as below :
ErrorException in Str.php line 171:
mb_strtolower() expects parameter 1 to be string, array given
Can you please paste your server-side code. Thanks!
BTW, can you please provide some codes that I can use to replicate the issue? Thanks!
this is action code of pulling data -
$response = $this->apiResource->getQueryStringData('projects', array());
$datatable = [];
if (isset($response['records']) && !empty($response['records'])) {
$datatable = $response['records'];
}
$data = new Collection($datatable);
return Datatables::of($data)
->setTotalRecords(isset($response['total_count']) ? $response['total_count'] : 0)
->skipPaging()
->editColumn('account_mgr', function ($projectData) {
$fistName = isset($projectData['account_mgr']['name']) ? explode(' ', $projectData['account_mgr']['name']) : '';
return isset($fistName[0]) ? $fistName[0] : '';
})
->editColumn('project_mgr', function ($projectData) {
$fistName = isset($projectData['project_mgr']['name']) ? explode(' ', $projectData['project_mgr']['name']) : '';
return isset($fistName[0]) ? $fistName[0] : '';
})
->editColumn('project_coordinator', function ($projectData) {
$fistName = isset($projectData['project_coordinator']['name']) ? explode(' ', $projectData['project_coordinator']['name']) : '';
return isset($fistName[0]) ? $fistName[0] : '';
})
->editColumn('start_date', function ($projectData) {
return isset($projectData['start_date']) ? date(config('services.standard_date_formate'), strtotime($projectData['start_date'])) : '';
})
->editColumn('project_view_id', function ($projectData) {
return '<a href="/view-project/' . $projectData['id'] . '">' . $projectData['project_view_id'] . '</a>';
})
->editColumn('ConsultantCount', function ($projectData) {
return '<a href="/consultant-projects/' . $projectData['id'] . '">' . $projectData['ConsultantCount'] . '</a>';
})
->make(true);
Above is sample data response from server :
[incomplete_results] =>
[total_count] => 2
[records] => Array
(
[0] => Array
(
[id] => 1
[project_view_id] => 00001
[client_id] => 1
[project_category_id] =>
[start_date] => 2017-01-20
[client_country_id] => 1
[client_contact_id] => 2
[account_mgr_id] => 1
[service_line_id] => 3
[project_coordinator_id] => 5
[project_mgr_id] => 1
[initial_activity_template_id] => 1
[repeat_activity_template_id] => 3
[status] => open
[project_name_id] => 2
[project_short_code] => HAL-AUS-TRA-WE
[closure_remarks] =>
[closure_date] =>
[created_by] => 9
[ConsultantCount] => 0
[client] => Array
(
[id] => 1
[client_group_id] => 1
[name] => Halliburton
[country_id] => 1
[status] => 1
[created_by] => 1
)
[client_country] => Array
(
[id] => 1
[name] => Australia
[country_code] => 61
[status] => active
[telephone_isd_code] => 61
[region] => Asia & Pacific
)
[client_contact] => Array
(
[id] => 2
[client_id] => 1
[project_name_id] => 2
[name] => Mike Smith
[designation] => Australia
[email] => [email protected]
[phone] => 2147483647
[country_id] => 1
[city] => Sydney
)
[service_line] => Array
(
[id] => 3
[name] => Training
)
[account_mgr] => Array
(
[id] => 1
[name] => anthonysmith
[email] => [email protected]
[country_id] => 1
[reporting_mgr_id] => 1
[employee_group_id] => 1
[access_right_id] => 1
)
[project_name] => Array
(
[id] => 2
[name] => Well Testing
)
[project_coordinator] => Array
(
[id] => 5
[name] => Daniel Lee
[email] => [email protected]
[country_id] => 2
[reporting_mgr_id] => 1
[employee_group_id] => 2
[status] => active
)
[project_mgr] => Array
(
[id] => 1
[name] => anthonysmith
[email] => [email protected]
[country_id] => 1
[reporting_mgr_id] => 1
[employee_group_id] => 1
[status] => active
)
[consultant_projects] => Array
(
)
)
Sorry for late response. I rarely use collection on my projects so this may took me some time to fix. If you can, please do not hesitate to submit a PR.
hi @yajra , first thanks for your very powerful Package.
second : sry for my bad english ;)
i have same problem and check this a lot.
and i fix it for my issue.
i think its problem when we have "name" in js columns and this "name" column is not exist in database Table.
my problem is:
{ data: 'role', name: 'role' },
and i have not role in my DB table
so i change it to
{ data: 'role', name: 'role_id' },
and this is work fine. :)
hope i can help.
sry for my bad english again! ;)
@yajra
I'm currently having this issue, it occurs when a model has relations. For instance this code $users = User::select(['id','name', 'email','created_at'])->with('profile')->get();
will output that same error because of user relationship with profile. The error is coming from Yajra\Datatables\Engines\CollectionEngine line 131. I'm doing a PR on this
Most helpful comment
hi @yajra , first thanks for your very powerful Package.
second : sry for my bad english ;)
i have same problem and check this a lot.
and i fix it for my issue.
i think its problem when we have "name" in js columns and this "name" column is not exist in database Table.
my problem is:
{ data: 'role', name: 'role' },and i have not role in my DB table
so i change it to
{ data: 'role', name: 'role_id' },and this is work fine. :)
hope i can help.
sry for my bad english again! ;)