-
Notifications
You must be signed in to change notification settings - Fork 227
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
Is orthogonal data supported with this gem? #269
Comments
Add this in your JS:
|
Thanks n-rodriguez.
It looks like the issue arises because of the #sanitize method
Is there a way to go around this? |
Ok, Im making some progress: Here is some new code:
then in js, I can do Thanks! |
I'm also trying to use orthogonal data but can't figure how to do with this gem. |
I'm trying to modify sanitize method like this, it return a json object correctly formatted but now I've some issue on JS side. def sanitize(data)
data.map do |record|
if record.is_a?(Hash)
record
elsif record.is_a?(Array)
record.map { |td| ERB::Util.html_escape(td) }
else
record.update(record){ |_, v| ERB::Util.html_escape(v) }
end
end
end |
@n-rodriguez Any thoughts on this? |
Hi! It could be supported. Nowadays the data is assumed to be html content so it's html escaped to avoid XSS attacks. What you want is json all the way so : Override the def data
records.map do |record|
{
id: record.id,
title: { title: record.title }
}
end
end
private
def sanitize(data)
data.map do |record|
if record.is_a?(Array)
record.map { |td| ERB::Util.html_escape(td) }
elsif record.is_a?(Hash)
if options[:json_content]
record
else
record.update(record) { |_, v| ERB::Util.html_escape(v) }
end
end
end
end and in the controller : def index
respond_to do |format|
format.html
format.json { render json: PostDatatable.new(params, json_content: true) }
end
end And in Coffee/JS : $ ->
$('#posts-datatable').dataTable
processing: true
serverSide: true
ajax: $('#posts-datatable').data('source')
pagingType: 'full_numbers'
columns: [
{ data: 'id' }
{
data: 'title',
render: (data, type, row)->
console.log(data)
if data?
data.title
else
''
}
] |
BTW I would use https://github.com/jbox-web/ajax-datatables-rails#using-view-decorators to avoid this kind of lengty methods : # before
def data
records.map do |record|
{
id: record.id,
scan_timestamp: raw({ data: record.effective_date.in_time_zone('Eastern Time (US & Canada)').strftime("%I:%M%p %Z %d-%b-%y"), display:"hello" }.to_json
}
end
end
# after
def data
records.map do |record|
{
id: record.id,
scan_timestamp: { data: record.decorate.effective_date, display: 'hello' }
}
end
end |
Added in the README : https://github.com/jbox-web/ajax-datatables-rails#tutorial |
I'm trying to specify a def data
records.map do |record|
{
id: record.id,
build_number: { display: record.build_number, sort_by: record.build_number.to_i },
}
end
end $(document).ready(function(){
$('#builds-datatable').DataTable({
// ...
columns: [
{ data: "id"},
{ data: "build_number",
render: {
_: 'display',
sort: 'sort_by',
}
}
]
});
});
I have added Any help you can offer is greatly appreciated. Thank you for creating and maintaining such a useful gem! |
In my data table I have the following column definition:
In my SearchResultDatatable#data method I have
This is not working - I get the datatables.net/tn/4 error because
{name: record.supplier.try(:name)}
gets serialized as a string not an object- so data.name returns undefined.
Any thoughts on how to fix this?
The text was updated successfully, but these errors were encountered: