Hi Carlos,

Here the full class source code.
Tested and working.
You can add to Royale source code tree.

////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.royale.jewel.beads.controls.datagrid
{
import org.apache.royale.core.IBead;
import org.apache.royale.jewel.DataGrid;
import org.apache.royale.core.IStrand;
import org.apache.royale.jewel.beads.views.DataGridView;
import org.apache.royale.events.MouseEvent;
import org.apache.royale.jewel.supportClasses.datagrid.DataGridButtonBar;
import org.apache.royale.collections.Sort;
import org.apache.royale.collections.SortField;
import org.apache.royale.collections.IArrayListView;
import org.apache.royale.jewel.supportClasses.datagrid.DataGridColumn;

public class DataGridSortBead implements IBead
{
public function DataGridSortBead()
{
super();
}
private var dg:DataGrid;

private var descending:Boolean;
/**
* @copy org.apache.royale.core.IBead#strand
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
public function set strand(value:IStrand):void
{
dg = value as DataGrid;
(dg.view as DataGridView).header.addEventListener(MouseEvent.CLICK,
mouseClickHandler, false);
}
/**
* @private
*/
private function mouseClickHandler(event:MouseEvent):void
{
var dgView:DataGridView = dg.view as DataGridView;
var buttonBar:DataGridButtonBar = (dgView.header as DataGridButtonBar);
// probably down on one button and up on another button
// so the ButtonBar won't change selection
if (event.target == buttonBar) return;
var column:DataGridColumn = event.target.data as DataGridColumn;
var collection:IArrayListView = dg.dataProvider as IArrayListView;
if (collection && collection.length)
{
if (collection.sort && collection.sort.fields[0].name == column.dataField)
descending = !descending;

var sort:Sort = new Sort();
var sortField:SortField = new SortField(column.dataField, false,
descending);

sort.fields = [ sortField ];
collection.sort = sort;

(dgView.header as DataGridButtonBar).model.dispatchEvent(new Event(
"dataProviderChanged"));

// force redraw of column headers
collection.refresh();
dg.dataProvider = null;
dg.dataProvider = collection;
}
}
}
}

Hugo Ferreira <hferreira...@gmail.com> escreveu no dia quarta, 9/09/2020
à(s) 14:19:

> OK, thank you for the tips.
> I will try to it :)
>
> Carlos Rovira <carlosrov...@apache.org> escreveu no dia quarta, 9/09/2020
> à(s) 14:15:
>
>> Hi Hugo,
>>
>> some helpers:
>>
>> 1.- You can create a "DataGridSortBead" class in jewel library. package
>> should be: org.apache.royale.jewel.beads.controls.datagrid
>> 2.- add to jewel-manifest.xml
>> 3.- code will be similar to the MXRoyale version.
>>     a) in the strand method override you retrieve the bead view
>> (DataGridView)
>>     b) you create a listener for MouseEvent.CLICK
>>
>> (at that time if you put a trace in that handler you should see the traces
>> as you click a button in the button bar)
>>
>>      c) Finally you implement the sorting. That should be very similar to
>> MXRoyale code just taking into account that Jewel uses ArrayList and
>> ArrayListView for sorting.
>>
>> I think these are the main puzzle's pieces if you want to try it.
>>
>>
>>
>> El mié., 9 sept. 2020 a las 14:58, Hugo Ferreira (<hferreira...@gmail.com
>> >)
>> escribió:
>>
>> > "Now that you have a bit more experience"
>> > Comparing to Flex, not so much.
>> >
>> > "what do you think about trying to create a Jewel version of
>> > "DataGridSortBead""
>> > I think that I'm still very new to Royale and I never tried to create a
>> > bead but I can try and check other bead to chek how to implement one. If
>> > sucessed I will post here the source so any of you guys can add to
>> source
>> > tree.
>> >
>> > Carlos Rovira <carlosrov...@apache.org> escreveu no dia quarta,
>> 9/09/2020
>> > à(s) 13:42:
>> >
>> > > Hi Hugo,
>> > >
>> > > Sorting in Jewel is still not implemented sorry.
>> > > 'DataGridSortBead' is a bead from emulation library, so it will not
>> work
>> > > with Jewel.
>> > >
>> > > Now that you have a bit more experience with Royale and Jewel, what do
>> > you
>> > > think about trying to create a Jewel version of "DataGridSortBead" and
>> > > submit for review as PR? I think we need folks like you trying to take
>> > over
>> > > Royale and join us helping where is possible. What do you think?
>> > >
>> > > Thanks
>> > >
>> > > El mié., 9 sept. 2020 a las 11:07, Hugo Ferreira (<
>> > hferreira...@gmail.com
>> > > >)
>> > > escribió:
>> > >
>> > > > Hello,
>> > > >
>> > > > I have a Jewel DataGrid.
>> > > > I see that Jewel DataGrid uses a button in header, obviously for
>> > sorting.
>> > > > Clicking nothing happens.
>> > > > Once almost every property is added thru beads, I searched and found
>> > this
>> > > > bead: DataGridSortBead but after I added it the DataGrid shows empty
>> > > > without any error in console.
>> > > >
>> > > > What I'm doing wrong here ?
>> > > >
>> > >
>> > >
>> > > --
>> > > Carlos Rovira
>> > > http://about.me/carlosrovira
>> > >
>> >
>>
>>
>> --
>> Carlos Rovira
>> http://about.me/carlosrovira
>>
>

Reply via email to