Assign GetRowClass-Handler in codebehind

  1. #1

    Assign GetRowClass-Handler in codebehind

    Hello,

    as described in the Example Marking Records I need to change the background color of multiple rows in my gridpanel in certain situations.

    Because I`ve implemented the Grid within a user control and the name of the handler function is dynamic, I need to assign the GetRowClass-Handler in codebehind.

    If I try to assign the name of the handler function directly, it gets never assigned:
    <style type="text/css">
        .past {
            background:red;
        }
        .future {
            background:green;
        } 
    </style>
    
    function <%= this.ClientID %>.GetRowClass(record) {
        if (record.get('ValidTo') < new Date() ) {
            return 'past';
        }
        if (record.get('ValidFrom') > new Date() ) {
            return 'future';
        }
    }
    _resourceConstraintDataGridView.GetRowClass.Fn = this.ClientID + ".GetRowClass"; // does not have an efffect
    After discovering this post, I tried out the workaround which was posted there. But also the workaround does not work for me (error: "JFunction is not serializeable").

    JFunction fn = new JFunction();
    
    fn.Fn = this.ClientID + ".GetRowClass";
    
    _resourceConstraintDataGridView.GetRowClass = fn; // raises an Exception with message "JFunction is not serializeable"
    I`m using Coolite 0.8.1.

    Is this Bug still existent ? Do you have any ideas ?

    Thx,
    Peter
  2. #2

    RE: Assign GetRowClass-Handler in codebehind

    Hi,

    Fixed. Please update from SVN

    Now GetRowClass is read only property. Use
    View1.GetRowClass.Fn = "fnName";
    Here is my test sample:
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Store1.DataSource = new object[]
            {
                new object[] {"Test"},
                new object[] {"Test"},
                new object[] {"Test"},
                new object[] {"Test"},
                new object[] {"Test"},
                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();
    
            GridPanel1.View[0].GetRowClass.Fn = this.ClientID + ".GetRowClass";
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Marking changed GridPanel - Coolite Toolkit Examples</title>
        
        <style type="text/css">
            .dirty-row {
                background:#FFFDD8;
            }
            .new-row {
                background:#c8ffc8;
            } 
        </style>
    </head>
    <body>    
        <form id="form1" runat="server">
            <script type="text/javascript">
                var insertRecord = function () {
                    var grid = <%= GridPanel1.ClientID %>;
                    grid.insertRecord(0, {});
                    grid.getView().focusRow(0);
                    grid.startEditing(0, 0);
                };
                
                <%= this.ClientID %> = {};
                
                <%= this.ClientID %>.GetRowClass = function(record) {
                    if (record.newRecord) {
                        return 'new-row';
                    }
                    if (record.dirty) {
                        return 'dirty-row';
                    }
                };
            </script>  
            
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <h1>Marking Records</h1>
            <p>Demonstrates how to select the records  by color (just edit any cell or insert new record).</p>
           
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:ArrayReader>
                        <Fields>
                            <ext:RecordField Name="TestCell" />                       
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </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">
                            <Editor>
                                <ext:TextField ID="TextBox1" runat="server" />
                            </Editor>
                        </ext:Column>                    
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView ID="GridView1" runat="server" >
                    </ext:GridView>
                </View>
                <Buttons>
                    <ext:Button ID="Button1" runat="server" Text="Insert record" Icon="Add">
                        <Listeners>
                            <Click Fn="insertRecord" />
                        </Listeners>
                    </ext:Button>
                </Buttons>
            </ext:GridPanel>  
        </form>
    </body>
    </html>

Similar Threads

  1. [CLOSED] adding handler listener in codebehind
    By ashton.lamont in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: May 05, 2010, 4:50 PM
  2. rowIndex in GetRowClass - possible?
    By Tbaseflug in forum 1.x Help
    Replies: 2
    Last Post: Sep 23, 2009, 10:25 PM
  3. Replies: 0
    Last Post: Apr 14, 2009, 6:10 PM
  4. GridPanel GetRowClass
    By louis in forum 1.x Help
    Replies: 4
    Last Post: Mar 04, 2009, 11:15 AM
  5. add maximize handler code via codebehind
    By sashe in forum 1.x Help
    Replies: 2
    Last Post: May 27, 2008, 9:30 AM

Posting Permissions