• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 748
  • Last Modified:

How to make an editable cell in mx:DataGrid have maxChars="25"

When I defined my datagrid column like this:

<mx:DataGrid editable="true">
    <mx:DataGridColumn headerText="Code"/>
</mx:DataGrid>

the text could flow on and on, and I wanted to limit the inputtable characters to 25. So I tried to create a MXML component instead that looks like this:

<mx:TextInput maxChars="25">
</mx:TextInput>

and then set the mx:DataGridColumn to:

<mx:DataGridColumn itemRenderer="myTextInputRenderer"/>

and the text still won't stop at 25 characters.

Anybody have any ideas? Thanks.
0
elepil
Asked:
elepil
  • 2
  • 2
1 Solution
 
lexxwernCommented:
Set it to the itemEditor not itemRenderer :-)
<mx:DataGrid editable="true">
    <mx:DataGridColumn headerText="Code">
       <mx:itemEditor>
         <mx:Component>
            <mx:TextInput maxChars="25"/>
         </mx:Component>
       </mx:itemEditor>
    </mx:DataGridColumn>
</mx:DataGrid>
 
// or
 
<mx:DataGridColumn itemEditor="myTextInputRenderer"/>

Open in new window

0
 
elepilAuthor Commented:
Hello again, lexxwern. :)

Your recommendations both worked as far as the maxChars issue, but both had the same odd repercussion. Here's how I did the inline one:

<mx:DataGridColumn headerText="Code">
    <mx:itemEditor>
        <mx:Component>
            <mx:TextInput maxChars="25" text="{data.code}"/>
        </mx:Component>
    </mx:itemEditor>
</mx:DataGridColumn>

When the datagrid displays, the value in the cell is not showing. I have to click it (to give it focus) before I would see the value, and I'm not sure why it's behaving that way.

I tried doing it with a separate MXML component as you recommended:

<mx:DataGridColumn itemEditor="myTextInputRenderer"/>

and the myTextInputRenderer has only this:

<?xml version="1.0" encoding="utf-8"?>
<mx:TextInput xmlns:mx="http://www.adobe.com/2006/mxml"
      maxChars="25" text="{data.code}">
</mx:TextInput>

Again, I get the same exact problem where the data won't show until I click the cell. Do you know why this is happening?
0
 
lexxwernCommented:
Okay, I think the dataField needs to be defined. Try this:

<mx:DataGridColumn headerText="Code" dataField="code">
    <mx:itemEditor>
        <mx:Component>
            <mx:TextInput maxChars="25" text="{data.code}"/>
        </mx:Component>
    </mx:itemEditor>
</mx:DataGridColumn>
 
// or
 
<mx:DataGridColumn itemEditor="myTextInputRenderer" dataField="code"/>

Open in new window

0
 
elepilAuthor Commented:
DOH! That was it, hehe. It's getting late here, I'm so tired I didn't even see that. I'm going to bed, and thank you very much for all your help.
0

Featured Post

Eye-catchers on the conference table

Challenge: The i-unit group was not satisfied with the audio quality during remote meetings. They were looking for a portable solution with excellent audio quality for use in their conference room but also at their client’s offices.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now