Comments (7)
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.
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.
KVision 0.0.36 is released. The guide and the examples have been updated.
from kvision.
+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.
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:
- The
Element
class does not have the externalfocus()
orstyle
modifiers defined so cannot be set here until they are added to KVisionElement
s. - 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).
- 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.
@BreadMoirai just for your reference, I'm able to get it working, looks a bit like this:
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.
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)
- Static resources missing after running gradle script for deployment. HOT 2
- Request - add Widget level drag & drop HOT 2
- Request - documentation/showcase-demos for using Kotlin-ringui and Kotlin-mui HOT 3
- Request - docs and/or support for JSX-like inclusion of own components in dsl HOT 3
- Task :jsProcessResources FAILED HOT 1
- Request - generate README.md from intellij plugin
- SimplePanel.add - Uncaught TypeError: Cannot read properties of undefined HOT 2
- Cannot read properties of null (reading 'x') HOT 13
- Error Deploying to Heroku - no main manifest attribute, in build/libs/uat-1.0.0-SNAPSHOT.jar HOT 8
- ResizeObserver loop completed with undelivered notifications. HOT 2
- Fetching and displaying data with Popover in Tabulator HOT 2
- request url of KVService is using related path instead of absolute path HOT 2
- Tabulator vertical scrolling issue HOT 7
- Initial value for DateTime control HOT 1
- Request - support for crossorigin attribute in Image (and others) HOT 1
- Ability to intercept image load errors HOT 2
- Component lifecycle HOT 6
- StackPanel seems to not indexing components properly HOT 4
- Wrong module in kvision.gitbook.io. HOT 1
- trying to generate .pot files HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kvision.