Skip to content

Commit

Permalink
add jsrender for DataTables
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Jan 14, 2025
1 parent 8520762 commit b82b6dd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ID = "__id"
const DATAKEY = "rows"
const DataTableSelection = Vector{Dict{String, Any}}

struct2dict(s::T) where T = Dict{Symbol, Any}(zip(fieldnames(T), getfield.(Ref(s), fieldnames(T))))
struct2dict(s::T) where T = OrderedDict{Symbol, Any}(zip(fieldnames(T), getfield.(Ref(s), fieldnames(T))))

#===#

Expand Down Expand Up @@ -580,6 +580,12 @@ end
Stipple.render(tables::AbstractArray{<:DataTable}) = render.(tables)
Stipple.render(tables::AbstractArray{DataTablePagination}) = render.(tables)

function Stipple.jsrender(t::T, args...) where {T<:DataTable}
rt = data(t)
rt["columns"] = [OrderedDict(k => Stipple.jsrender(v) for (k, v) in c) for c in rt["columns"]]
rt
end

# function to autogenerate entries for js_mounted to make Tables from Quasar1 compatible with tables from Quasar2
# Background: the field 'data' has been renamed to 'rows' in Quasar 2
# This function autogenerates entries that set the 'data' field of tables to the 'rows' field. As Vue3's mechanism
Expand Down Expand Up @@ -611,7 +617,7 @@ end

#===#

function Base.parse(::Type{DataTablePagination}, d::Dict{String,Any})
function Stipple.stipple_parse(::Type{DataTablePagination}, d::Dict{String,Any})
dtp = DataTablePagination()

dtp.sort_by = get!(d, "sortBy", "desc") |> Symbol
Expand Down

0 comments on commit b82b6dd

Please sign in to comment.