Flex: Add a new row to the top of the ordered DataGrid

Source: Internet
Author: User
<? XML version = "1.0" encoding = "UTF-8"?>
<! -- Http://yecon.blog.hexun.com/29905010_d.html -->
<! -- Http://www.slsay.com -->
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml"
Layout = "vertical"
Verticalalign = "Middle"
Backgroundcolor = "white"
Creationcomplete = "Init ();">
<Mx: SCRIPT>
<! [CDATA [
Import MX. Collections. arraycollection;
Import flash. utils. bytearray;
Public var objs: arraycollection = new arraycollection ();
Private function Init (): void
{
VaR OBJ: Object = new object ();
OBJ. Name = "Aslan ";
Objs. additem (OBJ );
OBJ = new object ();
OBJ. Name = "Shek ";
Objs. additem (OBJ );
OBJ = new object ();
OBJ. Name = "yecon ";
Objs. additem (OBJ );
OBJ = new object ();
OBJ. Name = "slsay ";
Objs. additem (OBJ );
OBJ = new object ();
OBJ. Name = "welcome ";
Objs. additem (OBJ );
OBJ = new object ();
OBJ. Name = "Haha ";
Objs. additem (OBJ );
DG. dataprovider = objs;
}
Private function clone (source: Object ):*
{
VaR myba: bytearray = new bytearray ();
Myba. writeobject (source );
Myba. Position = 0;
Return (myba. readobject ());
}
Private function addobj (): void
{
VaR temp: array = clone (objs. toarray ());
Objs = new arraycollection (temp );
DG. dataprovider = objs;
VaR OBJ: Object = new object ();
OBJ. Name = "";
Objs. additemat (OBJ, 0 );
}
]>
</MX: SCRIPT>
<Mx: button width = "150" label = "Add new row" Click = "addobj ();"/>
<Mx: DataGrid id = "DG" editable = "true" width = "50%" Height = "80%">
<Mx: columns>
<Mx: datagridcolumn headertext = "name" datafield = "name" editable = "true"/>
</MX: columns>
</MX: DataGrid>
</MX: Application>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.