Skip to content

Columns with structured data types #408

Open
@AndrewKvalheim

Description

@AndrewKvalheim

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions