Giter Club home page Giter Club logo

Comments (7)

rjaros avatar rjaros commented on August 12, 2024 2

I've already created formatter and formatterFunction properties in ColumnDefinition to allow custom formatters. The same can be done for custom editors - we can just add editorFunction next to editor property.

from kvision.

rjaros avatar rjaros commented on August 12, 2024 1

I have committed some quite sophisticated code (Kotlin power! :-) that will allow to directly embed most KVision components inside tabulator cells. It works both for formatters and editors, with additional type-safe access to Kotlin data model. There are some glitches, e.g. the Select component doesn't work because of click event listeners conflicts, but I've added new SimpleSelect component, that should be fine for most use cases.

I'll put some examples in the showcase project and in the guide after the next realease is published.

from kvision.

rjaros avatar rjaros commented on August 12, 2024 1

KVision 0.0.36 is released. The guide and the examples have been updated.

from kvision.

robert-cronin avatar robert-cronin commented on August 12, 2024

+1 for this, Tabulator doesn't look like it has a built-in date editor but would be useful for a lot of applications

from kvision.

robert-cronin avatar robert-cronin commented on August 12, 2024

I have tried this with the standard tabulator module and it looks like the module will need to be modified a little to allow it. The code I tried looks like the following:

val dateEditor = fun(cell: CellComponent, onRendered: dynamic, success: dynamic, cancel: dynamic, editorParams: dynamic): Element {
    //cell - the cell component for the editable cell
    //onRendered - function to call when the editor has been rendered
    //success - function to call to pass the successfuly updated value to Tabulator
    //cancel - function to call to abort the edit and return to a normal cell
    //editorParams - params object passed into the editorParams column definition property

    //create and style editor
    var editor = document.createElement("input")

    editor.setAttribute("type", "date")

    //create and style input
    editor.style.padding = "3px";
    editor.style.width = "100%";
    editor.style.boxSizing = "border-box";

    //Set value of editor to the current value of the cell
    editor.setAttribute("value", Moment(cell.getValue() as String).format("YYYY-MM-DD"))

    //set focus on the select box when the editor is selected (timeout allows for editor to be added to DOM)
    onRendered(fun(){
        editor.focus()
        editor.style.css = "100%"
    })

    //when the value has been set, trigger the cell to update
    fun successFunc(){
        success(Moment(editor.getAttribute("value") ?: "", "YYYY-MM-DD").format("DD/MM/YYYY"))
    }

    editor.addEventListener("change", {successFunc()})
    editor.addEventListener("blur", {successFunc()})

    //return the editor element
    return editor
}

Then I call this Anonymous function in the ColumnDefinition:

...
ColumnDefinition("DATE", "date", editor = dateEditor, formatter = Formatter.DATETIME),
...

But there are a few problems with this approach:

  1. The Element class does not have the external focus() or style modifiers defined so cannot be set here until they are added to KVision Elements.
  2. The dateEditor above depends on the momentjs library (this is something I've developed in a fork of KVision and will be committed with my next PR).
  3. Currently, the editor parameter does not except dynamic inputs and so cannot accept Anonymous functions.
    Hope this helps clarify what needs to be done. If I get time, I might submit a PR to fix these issues (with Robert's blessing of course) since our app would depend on something like this too.

from kvision.

robert-cronin avatar robert-cronin commented on August 12, 2024

@BreadMoirai just for your reference, I'm able to get it working, looks a bit like this:
image
Here is the code I used:

val dateEditor = fun(cell: CellComponent, onRendered: dynamic, success: dynamic): dynamic {
    //cell - the cell component for the editable cell
    //onRendered - function to call when the editor has been rendered
    //success - function to call to pass the successfuly updated value to Tabulator

    //create and style editor
    val editor = document.createElement("input")

    editor.setAttribute("type", "date")

    //create and style input
    editor.setAttribute("padding", "3px")
    editor.setAttribute("width", "100%")
    editor.setAttribute("boxSizing", "border-box")

    //Set value of editor to the current value of the cell
    editor.setAttribute("value", Moment(cell.getValue() as String).format("YYYY-MM-DD"))

    //when the value has been set, trigger the cell to update
    fun successFunc(){
        success(Moment(editor.getAttribute("value") ?: "", "YYYY-MM-DD").format("DD/MM/YYYY"))
    }

    editor.addEventListener("change", {successFunc()})
    editor.addEventListener("blur", {successFunc()})

    //return the editor element
    return editor
}
.....
 ColumnDefinition("DATE", "date", formatterFunction = dateEditor),
.....

Note: this depends on the moment.js module

from kvision.

robert-cronin avatar robert-cronin commented on August 12, 2024

That'll come in handy, It must have taken you a while to do all that, but makes KVision even more useful

from kvision.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.