Best Practice for Sharing Between CustomJS Code?

In my datatable application I find myself repeating code in control after control so that after any changes in either the rows or the columns that the user instigates, the width of each column is adjusted based on the maximum length of all visible strings in that column.

Is there some way for me to write code blocks that can be inserted into the CustomJS before runtime, or to make blocks that can be called from within CustomJS at runtime?

As an aside, if there is an easier way to get dynamic width on the table columns, please let me know. I couldn’t find it and rolled my own.

I don’t really have any input to give.CustomJS was created with fairly simpler use-cases in mind, so this gets to pushing the enveloped a bit. It’s say it’s a good opportunity for new folks to provide their own input and contributions to help make things better/simpler for these broader scenarios.

Otherwise, yes the options are basically just text munging, which might be as simple as basic Python text substitutions, or more complicated like Jinja or other templating.

There’s also nothing currently to “publish” helper functions that different CustomJS could use. That seems like a reasonable idea I’d be happy to advise anyone that wanted to work on it.

For the immediate term, a hacky workaround might be to put code in a CustomJSTransform (or any CustomJS-type model, really), and pass that around to the different real CustomJS that you care about, and they could execute them manually.

1 Like