Skip to content

Commit

Permalink
add props = :props and declare const DATAKEY for easy migration to Qu…
Browse files Browse the repository at this point in the history
…asar 2
  • Loading branch information
hhaensel committed Mar 29, 2024
1 parent 50a0169 commit d93a8e2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export cell_template, qtd, qtr
register_normal_element("q__table", context = @__MODULE__)

const ID = "__id"
const DATAKEY = "data" # has to be changed to `rows` for Quasar 2
const DataTableSelection = Vector{Dict{String, Any}}

struct2dict(s::T) where T = Dict{Symbol, Any}(zip(fieldnames(T), getfield.(Ref(s), fieldnames(T))))
Expand Down Expand Up @@ -235,7 +236,7 @@ end
change_inner_style::Union{Nothing,AbstractString,AbstractDict,Vector} = nothing,
rowkey::String = ID,
datakey::String = "$table.data",
datakey::String = "$table.$DATAKEY",
columnskey::String = "$table.columns",
kwargs...)
Expand Down Expand Up @@ -316,7 +317,7 @@ function cell_template(table::Symbol, ref_table::Union{Nothing,Symbol} = nothing
change_inner_class::Union{Nothing,AbstractString,AbstractDict,Vector} = nothing,
change_inner_style::Union{Nothing,AbstractString,AbstractDict,Vector} = nothing,
rowkey::String = ID,
datakey::String = "$table.data",
datakey::String = "$table.$DATAKEY",
columnskey::String = "$table.columns",
kwargs...)

Expand Down Expand Up @@ -348,10 +349,12 @@ function cell_template(table::Symbol, ref_table::Union{Nothing,Symbol} = nothing
inner_class === nothing && (inner_class = "")
for column in columns
slotname = isempty(column) ? "body-cell" : "body-cell-$column"
t = template("", "v-slot:$slotname=\"props\"", [td(
htmldiv("{{ props.value }}"; class = inner_class, style = inner_style, inner_kwargs...);
t = template("", "v-slot:$slotname=\"props\"", [
td(props = :props,
htmldiv("{{ props.value }}"; class = inner_class, style = inner_style, inner_kwargs...);
class, style, kwargs...
)])
)
])
push!(cell_templates, t)
end

Expand Down Expand Up @@ -407,7 +410,7 @@ function cell_template(table::Symbol, ref_table::Union{Nothing,Symbol} = nothing
qinput = "$typ" == "number" ? numberfield : textfield
slotname = isempty(column) ? "body-cell" : "body-cell-$column"
t = template("", "v-slot:$slotname=\"props\"", [
StippleUI.td(
StippleUI.td(props = :props,
qinput("", Symbol(value), :dense, :borderless, type = typ,
input__class = inner_class,
input__style = inner_style;
Expand Down Expand Up @@ -456,7 +459,7 @@ function table( fieldname::Symbol,
args...;
edit::Union{Bool, AbstractString, Vector{<:AbstractString}} = false,
rowkey::String = ID,
datakey::String = "$fieldname.data",
datakey::String = "$fieldname.$DATAKEY",
columnskey::String = "$fieldname.columns",
filter::Union{Symbol,String,Nothing} = nothing,
paginationsync::Union{Symbol,String,Nothing} = nothing,
Expand Down Expand Up @@ -521,7 +524,7 @@ function table( fieldname::Symbol, args...;
ref_table::Union{Nothing,Symbol} = nothing,
edit::Union{Bool, AbstractString, Vector{<:AbstractString}} = false,
rowkey::String = ID,
datakey::String = "$fieldname.data",
datakey::String = "$fieldname.$DATAKEY",
columnskey::String = "$fieldname.columns",
filter::Union{Symbol,String,Nothing} = nothing,
paginationsync::Union{Symbol,String,Nothing} = nothing,
Expand Down

0 comments on commit d93a8e2

Please sign in to comment.