Home > Action Script 3.0, Flex, Mobile > Spark Datagrid in Mobile – Basics Part 1

Spark Datagrid in Mobile – Basics Part 1

Here is the code created to use Spark DataGrid in Mobile application. The new Spark Datagrid gives so much freedom to a designer that it can revamp the entire look and feel of a datagrid. Although ADOBE discourages the use of Datagrid in Mobile application, I decided to give it a go just for exploring purpose.

Let’s jump on the example directly.

The Example is a Checklist for your day to day work. This article is the first installment of the entire series of Checklist application development. Here, I will add the contents in the datagrid at runtime which includes checkbox and a text.

Here, I have a mobile project with a Datagrid named “dgTaskGrid”.

<s:DataGrid id="dgTaskGrid" skinClass="skins.DatagridSkin"
					width="100%" height="100%"
					 verticalScrollPolicy="on" />

Let’s create an arrayCollection “taskItems” in the script part, which will be a Dataprovider for the Grid .

private var taskItems : ArrayCollection = new ArrayCollection();

In the declarations tab, I have a ArrayList named “checkList” which will have a two GridColumn child inside it.

<s:ArrayList id="checkList">
	<s:GridColumn width="50">
		<s:itemRenderer>
		<fx:Component>
			<s:GridItemRenderer textAlign="center" >
				<s:CheckBox label="" selected="{data.isFinished}" horizontalCenter="0"/>
			</s:GridItemRenderer>
			</fx:Component>
				</s:itemRenderer>
			</s:GridColumn>
			<s:GridColumn headerText=""
				  dataField="text"/>
		</s:ArrayList>

I have added checkbox component in the GridItemRenderer of the first column and second column will represent my text for the new task to be added.

I need to set the dataProvider and columns property of the grid “dgTaskGrid” to feed in the data. So updated Datagrid will have following code.

<s:DataGrid id="dgTaskGrid"
	    skinClass="skins.DatagridSkin"
	    width="100%" height="100%"
	    dataProvider="{taskItems}"
	    columns="{checkList}"
	    verticalScrollPolicy="on" />

If you look closely to my sample application, I am adding a row in the Datagrid at rumtime when I click the “Add” button. All I have to do is create an object which will include my new task text. Following is the code of the same.

protected function btnAddTask_clickHandler(event:MouseEvent):void
{
	var taskItem : Object = new Object();
	taskItem.text = txtTaskName.text;
	taskItem.isFinished = false;
	taskItems.addItem(taskItem);
	txtTaskName.text = "";
}

This includes pretty much everything to display the newly added task in the Datagrid.

Now, something about the styling part where I don’t want to show the usual look of the datagrid that includes the rows and columns.

For this purpose I have created a styleClass for the spark Datagrid where I have disable the following skin.

-        columnSeparator

-        rowSeparator

-        headerSeparator

Moreover, I  don’t have anything to show in the header part of the grid. So I am just setting the visible property of ”GridColumnHeaderGroup” to make it disappear.

That’s it. You can see how the application looks in the below screen shot when add a list of tasks to be completed.

 

 



Advertisement
  1. Mike
    July 13, 2011 at 11:57 am | #1

    can you show your styleClass for the spark Datagrid. i’m looking for a way to disable
    columnSeparator, rowSeparator, headerSeparator

    and how did you apply it to the grid?

  2. Mayur Thakor
    July 14, 2011 at 4:35 am | #2

    When you crate a style Class for your spark Datagrid, You will get “columnSeparator” as Skin Parts.

    To remove them, just remove these style parts. That should remove the Separators.

    <fx:Component id="columnSeparator" >
    	<s:Line>
            	<s:stroke>
                        <s:SolidColorStroke color="0xE6E6E6" weight="1" caps="square"/>
                    </s:stroke>
            </s:Line>
    </fx:Component>
    

    Same goes for “headerColumnSeparator” & “rowSeparator”. This should resolve your query.

  3. Jeremy
    August 10, 2011 at 7:19 pm | #3

    headerSeparator is different. how do modify or remove this one.

  4. Mayur Thakor
    August 16, 2011 at 9:39 am | #4

    Hi Jeremy,

    For your datagrid, just add class reference for “SparkSkin” in the “headerSeparatorSkin” as follow

    it removes the headerSeparator.

  5. Jeremy
    August 16, 2011 at 1:52 pm | #5

    Thank you

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.