Skip to content

Extend column_def() Column Styling Options #2

Open
@olajoke

Description

@olajoke

Description

This issue is an extension of the existing column_def(), which currently supports defining column properties such as name, width, and column_type. The goal is to enhance column_def() by incorporating column styling options from Cheetah Grid to allow users to customize column appearance (e.g., text alignment, font, colours) when using cheetah(), similar to how reactable allows column-level customization.

Existing Function of column_def()

column_def <- function(
  name = NULL,
  width = NULL,
  min_width = NULL,
  max_width = NULL,
  column_type = NULL,
  action = NULL
) {
  list(
    caption = name,
    width = width,
    minWidth = min_width,
    maxWidth = max_width,
    columnType = column_type,
    action = action
  )
}

Why Column Styling is Important?

  • Improved Readability: Customize fonts, alignment, and colors for better data presentation.
  • Conditional Formatting: Highlight specific rows or columns based on data values.
  • Shiny Integration: Dynamic styling updates based on user inputs.

Reference Documentation

👉 Cheetah Grid Column Styles API

Enhancements to Implement

Add Styling Parameters to column_def() by Introducing options such as:

  • text_align ("left", "center", "right")
  • font (e.g., "bold 14px Arial")
  • background_color (e.g., "#f0f0f0")
  • color (text color, e.g., "red")
  • border_color (e.g., "#ccc")

Updated Function Proposal:

column_def <- function(
  name = NULL,
  width = NULL,
  min_width = NULL,
  max_width = NULL,
  column_type = NULL,
  action = NULL,
  text_align = NULL,
  font = NULL,
  background_color = NULL,
  color = NULL,
  border_color = NULL
) {
  list(
    caption = name,
    width = width,
    minWidth = min_width,
    maxWidth = max_width,
    columnType = column_type,
    action = action,
    textAlign = text_align,
    font = font,
    backgroundColor = background_color,
    color = color,
    borderColor = border_color
  )
}

Task Breakdown

Expose Column Styling Options to R

  • Allow users to define column-specific properties such as textAlign, font, backgroundColor, and borderColor.
  • Edit the column_def() function to accept styling parameters.

Modify JavaScript to Apply Styles

  • Update the JavaScript widget to map R column styling options to Cheetah Grid’s column styling API.
  • Ensure that the styles are applied dynamically when rendering the grid.

Expected outcome with sample usage in R:

cheetah(mtcars, 
  columns = list(
    column_def(name = "mpg", text_align = "center", background_color = "lightblue"),
    column_def(name = "cyl", font = "bold 14px Arial", color = "red")
  )
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions