GridPanel + record.data, how can it refuse to work?

  1. #1

    I can't read any row field using record.data on a GridPanel, can I get some help?

    Hi guys, I have a simple GridPanel bound to a SqlDataSource control and I copied a grid from the samples to my code in order to render a Hyperlink on the cell, for some reason I simply can't access the current record data using any combination of:

    record["field"]
    record.field
    record.data["field"]

    Can I get some help?
    Thanks

    <ext:GridPanel ID="gridSearch" 
                runat="server" 
                Title="Search Results"
                Frame="true"
                Width="685"
                Height="330" StripeRows="True">
                <Store>
                    <ext:Store ID="Store1" runat="server" RemoteSort="true" DataSourceID="getSearchResults">
                        <AutoLoadParams>
                            <ext:Parameter Name="start" Value="0" Mode="Raw" />
                            <ext:Parameter Name="limit" Value="10" Mode="Raw" />
                        </AutoLoadParams>
                        <Reader>
                            <ext:JsonReader IDProperty="cID">
                                <Fields>
                                    <ext:RecordField Name="Name" />
                                    <ext:RecordField Name="Phone" />
                                    <ext:RecordField Name="Address" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <SortInfo Field="Name" Direction="ASC" />
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="Name" Header="Name" DataIndex="Name">  
                            <Renderer Handler="return '<b>' + record.data.Name + '</b>,' + record.data.Phone" />                 
                        </ext:Column>
                        <ext:Column DataIndex="Phone" Header="Phone" Width="110" />
                        <ext:Column DataIndex="Address" Header="Address" Width="170" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
    Last edited by paul-2011; Aug 11, 2010 at 4:18 PM. Reason: correct title
  2. #2
    Hi!
    Test with:
    
    var namePhone = function(value, metadata, record, rowIndex, colIndex, store) {
                    return '<b>' + record.data.Name + ' ' + record.data.Phone + '</b>';
                };
    
    
    <Renderer Fn="namePhone " />
    Maia.
    Coolite 1.0
    Last edited by Maia; Aug 12, 2010 at 5:26 PM.
  3. #3
    Quote Originally Posted by Maia View Post
    Hi!
    Test with:
    
    var namePhone = function(value, metadata, record, rowIndex, colIndex, store) {
                    return '<b>' + record.data.Name + ' ' + record.data.Phone + '</b>';
                };
    
    
    <Renderer Fn="namePhone " />
    Maia.
    Coolite 1.0
    Hi Maia, thanks for the support, the code works nicely with those fields but if I try to read a field that is not listed as a column it returns "undefined";


    This works:
    <script type="text/javascript" language="javascript">
        var namePhone = function (value, metadata, record, rowIndex, colIndex, store) {
            return '<a href="client.aspx?id='+ record.id+'">' + record.data.Name + '</a>';
        };
    </script>

    This doesn't work:
    <script type="text/javascript" language="javascript">
        var namePhone = function (value, metadata, record, rowIndex, colIndex, store) {
            return '<a href="client.aspx?id='+ record.data.id+'">' + record.data.Name + '</a>';
        };
    </script>
    Last edited by paul-2011; Aug 12, 2010 at 8:29 PM.
  4. #4
    Hi paul-2011,

    To access record.data.id, you have to configure an "id" Field in your Store.

    The record.id is an autogenerated value.
    Geoffrey McGill
    Founder
  5. #5
    Quote Originally Posted by geoffrey.mcgill View Post
    Hi paul-2011,

    To access record.data.id, you have to configure an "id" Field in your Store.

    The record.id is an autogenerated value.
    Awesome Geoffrey, that solves all my problems with multiple ids + GridPanel, in the end it was all about adding the necessary fields that don't need to be displayed as columns to the Store when you need to query them as a Parameter or on a Listener, Fn, etc ,etc, thank you so much!


    And thank you Maia very much as well!
    Last edited by paul-2011; Aug 13, 2010 at 2:33 AM.
  6. #6
            <ext:Store ID="Store1" runat="server" >
                   <Reader>
                      <ext:JsonReader AutoDataBind="true">
                         <Fields>
                            <ext:RecordField Name="infoBack_id" Type="Int"/>
                            <ext:RecordField Name="infoBack_subTime" Type="Date"/>
                            <ext:RecordField Name="infoType_name"/>
                            <ext:RecordField Name="track_mtConfirm"/>
                            <ext:RecordField Name="track_confirmTime" Type="Date"/>
                            <ext:RecordField Name="infoBack_subContext"/>
                            <ext:RecordField Name="track_mtContext"/>
                            <ext:RecordField Name="track_hadContext"/>
                            <ext:RecordField Name="sub_userId"/>
                            <ext:RecordField Name="con_userId"/>
                            <ext:RecordField Name="infoBack_remark"/>
                            <ext:RecordField Name="infoBack_version" Type="Int"/>
                            <ext:RecordField Name="track_id" Type="Int"/>
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
           <ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1" Frame="true" Title="紧急事务列表" Icon="Database" StripeRows="true" Height="500" AutoWidth="true" AutoScroll="true">
                                        <ColumnModel ID="ColumnModel1" runat="server">
                                            <Columns>
                                            <ext:RowNumbererColumn />
                                            <ext:Column DataIndex="infoBack_id" Header="序号" Width="10" Align="Center" Hidden="true"/>
                                            <ext:Column DataIndex="infoBack_subTime" Header="发起时间" Width="110" Align="Center" >
                                                <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d H:i')" />
                                            </ext:Column>
                                            <ext:Column DataIndex="infoType_name" Header="事件类型 " Width="90" Align="Center">
                                            </ext:Column>
                                            <ext:Column DataIndex="track_mtConfirm" Header="维护解决情况" Width="90" Align="Center"/>
                                            <ext:Column DataIndex="track_confirmTime" Header="最后确认时间" Width="110" Align="Center">
                                                <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d H:i')" />
                                            </ext:Column> 
                                            <ext:Column DataIndex="infoBack_subContext" Header="事件情况说明" Width="180" Align="Left"/>
                                            <ext:Column DataIndex="track_mtContext" Header="情况解决说明" Width="180" Align="Left"/>
                                            <ext:Column DataIndex="track_hadContext" Header="开发处理说明" Width="180" Align="Left"/> 
                                            <ext:Column DataIndex="sub_userId" Header="确认人(编辑部)" Width="90" Align="Center"/>
                                            <ext:Column DataIndex="con_userId" Header="确认人(运维部)" Width="90" Align="Center"/> 
                                            <ext:Column DataIndex="infoBack_remark" Header="备注" Width="180" Align="Center"/>
                                            <ext:Column DataIndex="track_id" Hidden="true"/>
                                            <ext:Column DataIndex="infoBack_version" Hidden="true" />
                                            </Columns>
                                            </ColumnModel>
                                            <LoadMask ShowMask="false" Msg="查询中..." />
                                            <BottomBar>
                                                <ext:PagingToolBar ID="PagingToolBar1" runat="server" PageSize="10" StoreID="Store1" />
                                            </BottomBar>
                                            <SelectionModel>
                                                <ext:RowSelectionModel runat="server" SingleSelect="true">
                                                    <Listeners>
                                                        <RowSelect Handler="#{FormPanel1}.getForm().loadRecord(record);"/>
                                                    </Listeners>
                                                </ext:RowSelectionModel>
                                            </SelectionModel>
                                    </ext:GridPanel>

Similar Threads

  1. [CLOSED] Move up/down gridpanel , delete gridpanel data can not work
    By gs_user in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 27, 2012, 12:37 AM
  2. Replies: 1
    Last Post: May 05, 2011, 3:47 PM
  3. Replies: 1
    Last Post: Jan 03, 2011, 1:49 PM
  4. GridPanel Add Record does not work in FireFox
    By r_honey in forum 1.x Help
    Replies: 2
    Last Post: Apr 13, 2009, 1:44 AM
  5. Ext.data.Record constructor
    By mthird in forum 1.x Help
    Replies: 0
    Last Post: Oct 14, 2008, 4:05 PM

Posting Permissions