Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set renderer and format in cellProperties #713

Closed
kapocris opened this issue May 27, 2013 · 10 comments
Closed

Set renderer and format in cellProperties #713

kapocris opened this issue May 27, 2013 · 10 comments

Comments

@kapocris
Copy link

Hello, apparently is not possible to set a custom format and render function at the same time. Please, have a look at my code:

Format works but the renderer function is never called.

cells: function (r, c, prop) {
                //Here we can change every single cell's properties.
                var cellProperties = {}
                cellProperties = {
                    readOnly: _viewModel.readOnly,                    
                    type: 'numeric', 
                    renderer: typeof (changesObj['row' + r]) != 'undefined' && typeof (changesObj['row' + r]['col' + prop]) != 'undefined' ?
                            editableUpdatedCellRenderer : editableCellRenderer
                    ,
                    format: _viewModel.inputMode == Forecasts.InputModes[0] ? '0' : '0.00'
                }
                return cellProperties
            },

Thanks

@setthase
Copy link

How you editableUpdatedCellRenderer and editableCellRenreder looks like? Probably you write it wrong - try add Handsontable.NumericCell.renderer.apply(this, arguments) at the bottom of yours renderer's.

@kapocris
Copy link
Author

They look exactly like this:

var editableCellRenderer = function (instance, td, row, col, prop, value, cellProperties) {
    Handsontable.TextCell.renderer.apply(this, arguments);
    $(td).addClass(cellProperties.cellClass)
    td.innerHTML = '<div class="editableCellInnerDiv">' + td.innerHTML + '</div>';
    return td;
};
var editableUpdatedCellRenderer = function (instance, td, row, col, prop, value, cellProperties) {
    Handsontable.TextCell.renderer.apply(this, arguments);
    $(td).addClass(cellProperties.cellClass)
    td.innerHTML = '<div class="editableUpdatedCellInnerDiv">' + td.innerHTML + '</div>';
    return td;
};

They are not being called at all.

If I leave the code like this:

cells: function (r, c, prop) {
                //Here we can change every single cell's properties.
                var cellProperties = {}                
                cellProperties = {
                    readOnly: _viewModel.readOnly,                    
                    type: {
                       renderer: typeof (changesObj['row' + r]) != 'undefined' && typeof (changesObj['row' + r]['col' + prop]) != 'undefined' ?
                        editableUpdatedCellRenderer : editableCellRenderer},

                }                
                return cellProperties
            },

it works but of course, no formatting.

@setthase
Copy link

Then fix it in these way:

cells: function (r, c, prop) {
                //Here we can change every single cell's properties.
                var cellProperties = {}                
                cellProperties = {
                    readOnly: _viewModel.readOnly,   
                    format: _viewModel.inputMode == Forecasts.InputModes[0] ? '0' : '0.00',
                    type: {
                       renderer: typeof (changesObj['row' + r]) != 'undefined' && typeof (changesObj['row' + r]['col' + prop]) != 'undefined' ?
                        editableUpdatedCellRenderer : editableCellRenderer},

                }                
                return cellProperties
            },

@kapocris
Copy link
Author

That works! . So the order was wrong?

Thank you very much for you help! very quick response. :)

@setthase
Copy link

Not order. You call rendered in wrong place in first code. You set type to 'numeric' and renderer to some other properties, but renderer must be inside type (must be a child of type) not a sibling.

@warpech
Copy link
Member

warpech commented May 29, 2013

You can also say that the order was wrong - yes.

Basically type means a collection of cell renderer and editor. So it will overwrite any renderer defined before it. But I think it is misleading behavior, I hate when it happens to me when I use other libraries :) So I will mark it as a low priority bug.

@warpech warpech reopened this May 29, 2013
@setthase
Copy link

I set priority to high, because this notation:

{
    type: 'some_type',
    renderer: someRenderer
}

doesn't work as desired. There is an error in code that doesn't apply order of these settings.

warpech added a commit that referenced this issue Jun 3, 2013
@warpech
Copy link
Member

warpech commented Jun 3, 2013

The above issue is now solved in HOT 0.9.3. This will now work as desired:

{
    type: 'some_type',
    renderer: someRenderer
}

@warpech warpech closed this as completed Jun 3, 2013
@davekos
Copy link

davekos commented Jun 9, 2014

I am looking for an example to set a row to the type 'DATE'. Most examples set the column to a specific type but I am working with Row Headers and Rows of data.

Would this above discussion be a good example or is there another better example out there?

@BOZii
Copy link

BOZii commented Jun 17, 2015

Implemented the above solution for changing formatting dynamically, in my case, after a ddl type is selected it changes the adjacent cell to proper format (ie. "Number" -> 0.00 , "Money" -> $0.00). My problem is that that it changes the formatting for the entire column, is there a way to change the format of just a single cell? without setting a custom renderer that checks the value and changes it based on regex. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants