CheckColumn value convert from Boolean to String

  1. #1

    CheckColumn value convert from Boolean to String



    Hello,


    I have an editable <ext:Gridpanel> for the user to enter phone types. They need to indicate if a type is valid or not.
    The column "PHONE_TYPE_ACTV_IND" uses a Convert to translate from Char(1) to true/false when loading the data.
    Now, when the data is inserted/updated, I need to send it has a Char(1) instead of true/false.
    Any help will be appreciated.


    
    
    <script language="javascript" type="text/javascript">
     function convert(v) {
         if (v == "Y") {
      return true;
         }
    
    
         if (v == "N") {
      return false;
         }
     }
    </script>
    ....
    
    
    <ext:RecordField Name="PHONE_TYPE_ACTV_IND" Type="Boolean">
     <Convert Fn="convert" />
    </ext:RecordField>
    
    
    .......
    
    
    <ext:CheckColumn ColumnID="PHONE_TYPE_ACTV_IND" Width="60" Editable="true" DataIndex="PHONE_TYPE_ACTV_IND" Header="Active?" Align="Center"/>
  2. #2

    RE: CheckColumn value convert from Boolean to String



    I have answered my own question. I use the BeforeRecordInserted event from the Store control and change the value in there.

    protected void storePhoneType_BeforeRecordInserted(object sender, BeforeRecordInsertedEventArgs e)
    {
        object activeValue = e.NewValues["PHONE_TYPE_ACTV_IND"];
    
    
        if (activeValue.ToString() == "true")
        {
     e.NewValues["PHONE_TYPE_ACTV_IND"] = "Y";
        }
        else if (activeValue.ToString() == string.Empty || activeValue.ToString() == "false")
        {
     e.NewValues["PHONE_TYPE_ACTV_IND"] = "N";
        }
    
    
    }
  3. #3

    RE: CheckColumn value convert from Boolean to String

    Hi Ernesto,

    I'm happy to hear you have this working now.*


    One minor optimization I noticed in your original code sample... you should be able to replace the <Convert> property with the following.


    Example


    <Convert Handler="return (v == 'Y');" />

    Hope this helps.


    Geoffrey McGill
    Founder
  4. #4

    RE: CheckColumn value convert from Boolean to String

    Actually, you can problem remove the parenthesis as well, but test to confirm.

    Example


    <Convert Handler="return v == 'Y';" />


    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 0
    Last Post: Dec 01, 2011, 6:43 AM
  2. Replies: 1
    Last Post: Feb 28, 2011, 8:13 AM
  3. Replies: 0
    Last Post: Oct 18, 2010, 2:48 AM
  4. Replies: 2
    Last Post: Aug 31, 2009, 6:03 PM
  5. How to convert a store to json string?
    By mcdonald in forum 1.x Help
    Replies: 2
    Last Post: Apr 13, 2009, 12:14 PM

Posting Permissions