2 Replies Latest reply on Jun 11, 2007 8:58 PM by appu19

    Id for TextInput in Datagrid

    appu19
      Hi ,
      I am using item renderer for textinput inside a datagrid. But it is not allowing me to give Id for the textinput.
      I have filter function where i need to use the TextInput id.
      Can anyone plss help me out in this regard.

      <mx:DataGrid id="dataGrid" bottom="10" top="38" right="10" left="10">
      <mx:columns>
      <mx:DataGridColumn headerText="Name" dataField="name">
      <mx:itemRenderer>
      <mx:Component>

      <mx:TextInput change="searchLog()" id="txtSearchLog1"/>

      </mx:Component>
      </mx:itemRenderer>

      </mx:DataGridColumn>
      <mx:DataGridColumn headerText="Description" dataField="desc"/>
      <mx:DataGridColumn headerText="Value" dataField="val"/>
      </mx:columns>
      </mx:DataGrid>

      I need to access txtSearchLog1...

      Thx in advance
        • 1. Re: Id for TextInput in Datagrid
          jlingwai
          put the textinput inside a canvas
          <mx:Component>
          <mx:Canvas>
          <mx:TextInput change="searchLog()" id="txtSearchLog1"/>
          </mx:Canvas>
          </mx:Component>
          • 2. Re: Id for TextInput in Datagrid
            appu19 Level 1
            Hi it dint work..can u plss give me other solution..i m getting Access of undefined property txtSearchLog1.

            my code is
            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientColors="[#f3f3f3, #ffffff]"
            initialize="initApp()" >

            <mx:Script>
            <![CDATA[
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.collections.ArrayCollection;

            public var gridData:ArrayCollection;
            private var colDataNames:Array = new Array();

            private function initApp():void
            {
            gridData = new ArrayCollection();
            gridData.addItem({name:"Matt", desc:"Matthews", val:"matt@myco.com"});
            gridData.addItem({name:"appu", desc:"aparajitha", val:"a@myco.com"});
            gridData.addItem({name:"krish", desc:"krishna", val:"k@myco.com"});
            loadData();
            drawGrid();
            }

            // creating an array collection with column names and mapping data
            public var gridColumns:ArrayCollection= new ArrayCollection([
            {colname:"Name",coldata:"name"},
            {colname:"Description",coldata:"desc"},
            {colname:"Value",coldata:"val"},
            ]);

            // draws the grid columns
            public function drawGrid():void{

            var coldescriptor:ArrayCollection = gridColumns;

            for(var i:int;i<coldescriptor.length;i++){
            colDataNames.push(coldescriptor .coldata);
            }

            }


            // refreshed the dataprovider for the search
            private function searchLog():void{
            gridData.refresh();
            }

            // loads the data
            public function loadData():void{
            dataGrid.dataProvider = gridData;
            setSearchFunction(searchData);
            }

            // sets the filter function to dataprovider
            public function setSearchFunction(searchFunction:Function):void{
            gridData.filterFunction = searchFunction;
            }

            // fired on text change, returns the text typed
            public function getSearchText1():String{
            return txtSearchLog1.text;
            }

            // searches the data based on simle string search
            private function searchData(item: Object):Boolean{
            //for(var i:int=0;i<colDataNames.length;i++){
            if(item[colDataNames[0]].toString().toLowerCase().indexOf(txtSearchLog1.text.toLowerCase( )) != -1){
            return true;
            }

            return false;
            }

            ]]>
            </mx:Script>




            <mx:Canvas width="100%" height="100%">
            <mx:Label x="10" y="12" text="Search"/>


            <mx:DataGrid id="dataGrid" bottom="10" top="38" right="10" left="10">
            <mx:columns>
            <mx:DataGridColumn headerText="Name" dataField="name">
            <mx:itemRenderer>
            <mx:Component>
            <mx:Canvas>
            <mx:TextInput change="parentDocument.searchLog()" id="txtSearchLog1"/>
            </mx:Canvas>
            </mx:Component>
            </mx:itemRenderer>

            </mx:DataGridColumn>
            <mx:DataGridColumn headerText="Description" dataField="desc"/>
            <mx:DataGridColumn headerText="Value" dataField="val"/>
            </mx:columns>
            </mx:DataGrid>

            </mx:Canvas>
            </mx:Application>

            thx in advance..