Open carles9000 opened 9 years ago
It's not that simple, unfortunately. You need to create a new editor in slick.editors.js (you could base it on IntegerEditor), see here.
You can keep the number of decimal places as a 'static' property of the editor by saying FloatEditor.decimalPlaces = 3;
after your FloatEditor definition. This wouldn't allow customisation of decimal places per-column though, you could add a column property if you needed that (a slightly messier approach).
Hi 6pac,
Slickgrid for me is fantastic and very powerful. Strange that such a basic need does not exist. Anyway will study your advice and keep searching the solution, but for users who are not experts in JavaScript is more complicated.
Thank you for your advice. Carlos.
Hi Carlos,
I added a FloatEditor to my repository. You'd be better off using my 'Alternate Master repo' anyway - it has a lot of bug fixes to the main code trunk (which is no longer maintained), including updates to the latest jQuery versions.
To use the FloatEditor just specify it as the column editor. By default it doesn't force any number of decimal places, it allows any number. However if you want to enforce a fixed number of decimal places you can either specify a editorFixedDecimalPlaces
property for an individual column, or set the FloatEditor DefaultDecimalPlaces
property to set it for all FloatEditors on the page.
So in example3-editing, you would put:
{id: "duration", name: "Duration", field: "duration", editor: Slick.Editors.Float, editorFixedDecimalPlaces: 2 },
to fix the decimal places to 2 just for that column, or set
Slick.Editors.Float.DefaultDecimalPlaces = 2;
to set the default for all editors on the page. The column setting will override the default.
Leaving out the settings or setting them to null
will turn off the forcing of fixed decimal places.
Hi Ben,
Great ! it's works and the code is very clear. I modifieed the formatter of this way for if someone want to use.
function FloatFormatter(row, cell, value, columnDef, dataContext) {
var nDecimals = 2;
if ( typeof columnDef.editorFixedDecimalPlaces == 'number' ){
var nDecimals = columnDef.editorFixedDecimalPlaces ;
}
return Number(value).toFixed( nDecimals );
}
Thanks for your help ! :-)
Carles.
Hi masters,
How I can edit with 2 decimals? Maybe other times I will need to 3 decimal, or more ...
Any examples or help please ?
Thanks in advance !
Carlos.