How to change the row back ground color when row is edited

Posted by: ashish-sharma on 14 September 2017, 12:14 pm EST

  • Posted 14 September 2017, 12:14 pm EST

    Hi I want to update the row color when user edit the so that use can easily identify which rows are he edited.

    I am using this code but it is not working

    Can you tell us how can I do it

    <!-- mark this as an Angular application and give it a controller –>

    <div ng-app=“app” ng-controller=“appCtrl”>

    <h1>Highlight Edited Cells</h1>

    &lt;p&gt;This is a &lt;b&gt;FlexGrid&lt;/b&gt; control. Edit some cells to see their background color change.&lt;/p&gt;
    &lt;wj-flex-grid items-source="data" initialized="initialized(s,e)"&gt;
    &lt;/wj-flex-grid&gt;
    

    </div>

    // define app, include Wijmo 5 directives
    var app = angular.module('app', ['wj']);
    
    // controller
    app.controller('appCtrl', function ($scope) {
    var row;
            var row1;
        // create some random data
        var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
            data = [];
        for (var i = 0; i < countries.length; i++) {
            data.push({
                country: countries[i],
                downloads: Math.round(Math.random() * 20000),
                sales: Math.random() * 10000,
                expenses: Math.random() * 5000
            });
        }
    
        // expose data as a CollectionView to get events
        $scope.data = new wijmo.collections.CollectionView(data);
        
        // highlight cells that have been edited
        $scope.initialized = function (s, e) {
            
            // 1: keep track of edited cells
            s.cellEditEnded.addHandler(function (s, e) {
           
           
                row1=s.rows[e.row].dataItem;
                
                 
            });
            
           s.beginningEdit.addHandler(function (s, e) {
           
                row =JSON.parse(JSON.stringify(s.rows[e.row].dataItem));
            });
            // 2: change the background of edited cells
            s.itemFormatter = function(panel, r, c, cell) {
           
               // if (panel == s.cells) {
                
                  //  cell.style.backgroundColor = changeColor() ? '#e0e0e0' : '';
                  
                }
            }
            
            function changeColor()
            {
            if(row== undefined) return;
           
             if(row1!==row)
             {
             return true;
             }
                return false;
                
                }
            
                    
            // utility to keep track of changed items
            
            
        }
    });
  • Posted 14 September 2017, 12:14 pm EST

    Hi Ashish,

    Please refer to the fiddle that implements the same. You need to update the following code snippet in the sample for highlighting row instead of cell.

    if (getChanged(r, c)) {
                               panel.rows[r].cssClass="wj-edit";
                                //cell.classList.add("wj-edit");
                            }

    Hope it helps!

    Please read the following blog:

    http://wijmo.com/blog/wijmo-com-will-soon-be-grapecity-com/

    Thanks,

    Manish Kumar Gupta

  • Posted 14 September 2017, 12:14 pm EST

    This fiddle is not working correctly it changes the color of rows if I select the row for editing and then if don’t change any thing and deselect the row it start showing different color.

    My requirement is that when user actually change the data of any column of grid then only the color of row should be changed.

    So how can we achieve this?

  • Posted 14 September 2017, 12:14 pm EST

    Hi Ashish,

    You need to check old and new value in cellEditEnding event.

    Please refer to the updated fiddle for the same.

    Thanks,

    Manish Kumar Gupta

  • Posted 14 September 2017, 12:14 pm EST

    Thanks

    Manish it is working for me.

    Can I change colour from this red to some other colour

  • Posted 14 September 2017, 12:14 pm EST

    Hi Ashish,

    You can change the red to other color by changing background color for wj-edit class defined in fiddle’s CSS section.

    Thanks,

    Manish Kumar Gupta

  • Posted 3 December 2018, 9:48 am EST

    Hi Manish,

    in angular if I have to change the row color of selected row it’s not working

    this.flexgrid; // instance of flex grid in component.ts
    
    eventFromBtn1() {
    	// chnage row 1 to 10 background color
    	for(let i = 0; i < 10 ; i++){
    		this.flexgrid.rows[i].cssClass = "highlight-red";
    	}
    }
    
    eventFromBtn2() {
    	// chnage row 1 to 10 background color to default 
    	for(let i = 0; i < 10 ; i++){
    		this.flexgrid.rows[i].cssClass = " "; // how to remove the added class
    	}
    }
    

    if you need any more details let me know.

    ~pritam

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels