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

After change event problems #744

Closed
gbssarma opened this issue Jun 4, 2013 · 16 comments
Closed

After change event problems #744

gbssarma opened this issue Jun 4, 2013 · 16 comments

Comments

@gbssarma
Copy link

gbssarma commented Jun 4, 2013

Hi

After changing the cell value i need to change the color for that cell and i need to repeat this for more than 10 cells.

But as of now this HandsOnTable is not supporting this feature.

Thanks
GBSSarma

@dittodhole
Copy link

handsontable is supporting this:

'afterChange': function (changes, source) {
    if (!changes) {
        return;
    }
    var instance = /* TODO for $handsontable-instance */;
    $.each(changes, function (index, element) {
        var change = element;
        var oldValue = change[2];
        var newValue = change[3];
        var rowIndex = change[0];
        var columnIndex = change[1];
        var cell = instance.getCell(rowIndex, columnIndex);
        var foreColor = /* TODO */;
        var backgroundColor = /* TODO */;
        cell.style.color = foreColor;
        cell.style.background = backgroundColor;
    });
}

@gbssarma
Copy link
Author

gbssarma commented Jun 5, 2013

I tried this one while debugging it is showing the color after that it is showing the previous color

@alvarotrigo
Copy link

I can not make it work: http://jsfiddle.net/8hv4z/13/

@dittodhole
Copy link

First "problem": your columnIndex does not start with 0, hence columnIndex more or less gives you just the pointer to your row-object (not the specific columnIndex).

Second problem:
jquery.handsontable.full.js line 8153ff

TD.className = '';
TD.removeAttribute('style');

The only hook afterwards is afterRender

@alvarotrigo
Copy link

I have started with columnIndex 0 and tried afterRender without success:
http://jsfiddle.net/8hv4z/14/

@dittodhole
Copy link

According to https://github.com/warpech/jquery-handsontable/wiki/Events the signature looks like this:

afterRender ()

Here's the workaround: http://jsfiddle.net/8hv4z/15/
Unfortunately this only changes the background- and foreColor of the last change...

But implementing a cache, as in http://jsfiddle.net/8hv4z/17/, makes changes "persistant"

@alvarotrigo
Copy link

Thanks @dittodhole. I have made an small modification in order to highlight only the cells if the new value is different than the old one:
http://jsfiddle.net/8hv4z/18/

Thanks again :)

@alvarotrigo
Copy link

Do you know if this could be possible using also on the previous version (Handsontable 0.8.23)?

I've noticed that afterRender is not available until version 9, and onBeforeChange was called onChange.

I am not yet using the last version because of a problem I found on the v.9.

@dittodhole
Copy link

Actually ...

According the events-docu

Events available since 0.8
onChange (changes: Array, source: String)

vs

Events available in 0.9
afterRender ()

but maybe the author knows how to implement the afterRender-event to 0.8

@papablopo
Copy link

i done in this way, thanks for share;

        afterChange: function (changes, data) {
                  if (!changes) {
                        return;
                     }
        $.each(changes, function (index, element) {
            var change = element;
            var rowIndex = change[0];
            var columnIndex = change[1];

            var oldValue = change[2];
            var newValue = change[3];

            var cellChange = {
                'rowIndex': rowIndex,
                'columnIndex': columnIndex
            };

            if(oldValue != newValue){
                cellChanges.push(cellChange);
            }
        });

            },
            afterRender: function () {
                    $.each(cellChanges, function (index, element) {
                        var cellChange = element;
                        var rowIndex = cellChange['rowIndex'];
                        var columnIndex = cellChange['columnIndex'];
                        var grilla = $('#grilla');
                         var td = grilla.handsontable('getCell', rowIndex, columnIndex );
                         td.className = 'pass'; 
                    });

i add
.handsontable .pass {
background: #ffc0ab;
}
at the handsontable css, and the cell is coloured inmediatily when u modify the value and not when modify another cel.

@ghost
Copy link

ghost commented Jul 24, 2013

Here's a shorter version, based on papablopo's version above:
Create cellChanges global variable, available everywhere in code, before initializing handsontable:
var cellChanges = [];

Add this code in afterChange handler:
cellChanges.push({'rowid':change[0], 'colid':change[1]});

Add this code in afterRender handler:
$.each(cellChanges, function (index, el) {
$('#dataTable').handsontable('getCell', el['rowid'], el['colid']).className = 'changed';
});

Add this css in your stylesheet:
.changed { background-color:#ddfaef !important; }

@dittodhole
Copy link

@pieroweb just what i've implemented months ago :) http://jsfiddle.net/8hv4z/17/ (actually a bit buggy, but ... gives the glimpse of an idea)

@udaiarora
Copy link

@pieroweb @dittodhole This isn't working as expected after you sort. Any workarounds?

@dittodhole
Copy link

@udaiarora any (non)working fiddle to play around with? (and to show us some implementation and where exactly your problem resides...)

@udaiarora
Copy link

I was talking about your fiddle- http://jsfiddle.net/8hv4z/17/ If you sort after change you will see the bug. But that can be fixed using sortIndex. Thanks anyways

@AMBudnik
Copy link
Contributor

I assume issue can be closed in lack of recent activity. If you would like to talk about your solutions here, we'll reopen the issue.

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

6 participants