Skip to content
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

Columns with structured data types #408

Open
AndrewKvalheim opened this issue Mar 18, 2022 · 0 comments
Open

Columns with structured data types #408

AndrewKvalheim opened this issue Mar 18, 2022 · 0 comments

Comments

@AndrewKvalheim
Copy link

AndrewKvalheim commented Mar 18, 2022

In past versions, datatables serialized into JSON that could represent columns containing arbitrarily structured data. For example, a column of post tags could contain an array—

def data
  records.map do |record|
    {
      title: record.title, # String
      tags:  record.tags,  # Array[String]
    }
  end
end

—and would be serialized as such:

{ "title": "Example", "tags": ["One", "Two"] }

This allowed the view to handle rendering:

columns = [
  { data: "title", render: (title) => escapeHtml(title) },
  { data: "tags", render: (tags) => tags.map((t) => `<span class="tag">${escapeHtml(t)}</span>`).join("") },
];

Since #199, returned records no longer contain data but fully rendered HTML views:

{ "title": "Example", "tags": "[&quot;One&quot;, &quot;Two&quot;]" }

This leaves a couple options for how to handle columns that contain structured data:

  • move the HTML rendering into the datatable’s data method
  • transport data as JSON-in-HTML and parse HTML in the view

Neither is very appealing to me. Is it intended that structured column types just not be used, or is there a better way to address this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant