-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
undefined method `fetch' for nil:NilClass #307
Comments
@Nittarab hi Im getting the same error. Any fix? |
@pvin Try to explain you situation, post your datatable.rb maybe I can help you. |
The mapping is wrong : You have : @view_columns ||= {
id: { source: 'User.id', searchable: false },
name: { source: 'User.name' },
surname: { source: 'User.surname' },
email: { source: 'User.email' },
role_name: { source: 'Role.name' }
} and def data
records.map do |record|
{
DT_RowId: m_dt_check_box_tag('users[]', record.id, false, class: 'dt-row-checkbox'),
name: link_to(record.name, record),
surname: link_to(record.surname, record),
email: link_to(record.email, record),
role_name: link_to(record.roles_name.join(','), record),
view: icon_to(SHOW_ICON, record),
edit: icon_to(EDIT_ICON, edit_user_path(record)),
delete: icon_to(DELETE_ICON,
record,
style: 'color:#f00',
method: :delete,
data: { confirm: I18n.t('datatable.confirm.delete') }),
permission: permission(record, options[:current_user])
}
end
end you should have def data
records.map do |record|
{
id: m_dt_check_box_tag('users[]', record.id, false, class: 'dt-row-checkbox'),
name: link_to(record.name, record),
surname: link_to(record.surname, record),
email: link_to(record.email, record),
role_name: link_to(record.roles_name.join(','), record),
DT_RowId: m_dt_check_box_tag('users[]', record.id, false, class: 'dt-row-checkbox'),
}
end
end |
Having the same problem: this is my code
The error im getting is |
Can you share ur js code? |
This is my js:
|
Example jQuery(document).ready(function() {
$('#blogs-datatable').dataTable({
"processing": true,
"serverSide": true,
"columnDefs": [{ "orderable": false, "targets": -1 }],
"ajax": $('#blogs-datatable').data('source'),
"pagingType": "full_numbers",
"columns": [
{"data": "id"},
{"data": "title"},
{"data": "description"},
{"data": "comments"},
{"data": "tag"}
]
// pagingType is optional, if you want full pagination controls.
// Check dataTables documentation to learn more about
// available options.
});
}); Have u added columns mentioned above?? Example columns": [ |
I forgot to include the columns |
I think it would be good for the library to detect this error and give a better error message. It had me for a while because I didn't suspect that a change in my JS would lead to an error like this in my backend. For anyone reading this that wasn't satisfied with the answers above, the solution is to make sure you declare the
|
Encountered this issue today. For me, a column defined in my JS code that was no longer in the backend( |
I'm using a lot of Datatable in my project. I can't understand what is going wrong the simplest Datatable that i have.
The error:
undefined method 'fetch' for nil:NilClass
is geted only when the table arr ordered by idThis is my datatable
I define de columns in this way:
And the datatable is inizialized in this whay:
The text was updated successfully, but these errors were encountered: