[CLOSED] Change cell background color in a grid

  1. #1

    [CLOSED] Change cell background color in a grid

    Hi,

    I need to change background color of cell in a grid, based on the if another cell data.
    I refer to this thread, but seems it is doesn't work with EXT.Net version 4.x
    Can i have your help?

    here is my sample code using the Renderer.

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
         protected void Page_Load(object sender, EventArgs e)
            {
                this.Store1.DataSource = new object[]
                {
                    new object[] {"Test"},
                    new object[] {"1"},
                    new object[] {"Test"},
                    new object[] {"Test"},
                    new object[] {"1"},
                    new object[] {"Test"},
                    new object[] {"Test"},
                    new object[] {"Test"},
                    new object[] {"Test"},
                    new object[] {"Test"},
                    new object[] {"Test"},
                    new object[] {"Test"},
                    new object[] {"Test"}
                };
    
                this.Store1.DataBind();
            }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            var RenderColor = function (value, meta, record) {
                var color = 'red';
                if (!record.data['TestCell'] == 1) {
                    color = 'green';
                }
    
                //or can set css tyle to meta.css
                meta.attr = 'style="background-color:' + color + ';"';
                return value;
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <form id="form1" runat="server">
            <ext:Store ID="Store1"
                runat="server"
                IgnoreExtraFields="false"
                PageSize="100">
    
                <Model>
                    <ext:Model ID="mdlDDModel" runat="server">
                        <Fields>
                            <ext:ModelField Name="TestCell" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
            <ext:GridPanel
                ID="GridPanel1"
                runat="server"
                StoreID="Store1"
                StripeRows="true"
                ClicksToEdit="1"
                Title="Test Grid"
                Width="600"
                Height="350"
                AutoExpandColumn="TestCell">
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="TestCell" Header="TestCell" DataIndex="TestCell">
                        </ext:Column>
                        <ext:Column ColumnID="ColorCell" Header="Color" DataIndex="ColorCell">
                            <Renderer Fn="RenderColor" />
                        </ext:Column>
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    Last edited by fabricio.murta; Mar 24, 2017 at 3:48 PM. Reason: No user feedback in 7+ days
  2. #2
    Hello @bapas1!

    Have you tried a more recent thread on the subject? The one you pointed is back from 2008. Here are some:
    - Gridpanel cell background color (2013)
    - cell background color (2015)

    I'm sure at least one of these will work for your scenario. Let us know if not.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello @bapas1!

    It's been some days since we replied to your inquiry. Do you still need help with this issue?

    Just to let you know, if you still don't post a follow-up here in 7+ days from now, we may mark this thread as closed -- but this will not mean you are unable to post here again once it is marked as closed, so as soon as you are able to provide us feedback on the issue, you are welcome to post here.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] grid cell background color - XTemplate
    By Z in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: May 17, 2015, 2:54 AM
  2. [CLOSED] Grid cell refresh and change column background color
    By chinninani in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 29, 2013, 3:30 PM
  3. Change GridPanel Cell background color
    By mis@adphk.com in forum 2.x Help
    Replies: 1
    Last Post: Mar 19, 2013, 1:43 AM
  4. Replies: 1
    Last Post: Jul 10, 2012, 11:16 AM
  5. How to Background color to the cell in Tree grid
    By rajputamit in forum 1.x Help
    Replies: 2
    Last Post: May 06, 2012, 4:16 PM

Posting Permissions