We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to render ColorPicker component for particular column while editing a record

Platform: JavaScript - EJ 2 |
Control: Grid

You can render the ColorPicker component for a particular column while editing a record using the “Cell Edit Template” feature of Grid component.

This is explained in the following sample code in which the ColorPicker component has been rendered using the “column.edit” property. The “rowDataBound” event triggers every time the row is bounded with data. Inside this event, the color value can able to be applied to the cell background.


var grid = new ej.grids.Grid({ 
        dataSource: data, 
        toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'], 
        editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, 
        columns: [ 
            { field: "OrderID", isPrimaryKey: true, headerText: "Order ID", width: 90 }, 
            { field: "CustomerID", headerText: "CustomerID", width: 90 }, 
            { field: "EmployeeID", headerText: "Employee ID", width: 90 }, 
                field: "Color", headerText: "Color", 
                edit: { 
                    create: function () { 
                        elem = document.createElement('input'); 
                        return elem; 
                    destroy: function () { 
                    read: function () { 
                        return colorPickerObj.value; 
                    write: function (args) { 
                        colorPickerObj = new ej.inputs.ColorPicker({ 
                            value: args.rowData[args.column.field] 
                width: 90 
        rowDataBound: rowdatabound, 
    function rowdatabound(args) { 
        var colIndex = grid.getColumnIndexByField("Color"); // Get the column index for Color 
        var colorTd = args.row.querySelectorAll("td.e-rowcell")[colIndex]; 
        // Get the cell from Grid rows 
        var color = colorTd.innerText;//get the colour value of the cell 
        colorTd.innerHTML = "<div style='padding:3px'>" + color + "</div>";//Append a div element inside the colour Td element 
        colorTd.querySelector("div").style.backgroundColor = args.data.Color; // Apply the background colour to the div element inside the td  




Apply Color in Grid Cells

Fig 1: Applying Color in Grid cells using RowDataBound event

Edit the color

Fig 2: Rendering ColorPicker Component while editing.


updating the color to the corresponding cell

Fig 3: Updating the selected color to the corresponding Cell.


JavaScript Demo

Angular Demo

You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile