Re: [flexcoders] Re: Sorting problem on date and numbers with null values, I think
[personal thoughts] Working on Flex projects you have to overcome some 'bug' troubles yourself. Adobe developers couldn't has enough time to help everybody to find solutions, they have to work for tasks depending on priority like all software development teams. Nothing can be perfect we have to trade-off. Performance can be a problem, but if there's a performance problem, you can still change your interface design to make it more acceptable for end users. Your developers are lucky to work with you even don't have to waste time for sorting functions. I have to find trade-off solutions more than these small tasks, even have to think about how to change interface, and defend for myself. End users and bosses wouldn't care where's the problem, what they know is if there's a problem, it's my problem, I have to fix it or make it better at least. For SDK code itself, I think we should let Adobe developers to judge whether it's a simple fix or not. They could have reasons we wouldn't know. George aceoohay wrote: The good news is I believe that the folks at Adobe are convinced this is a bug. The bad news is I was told that they aren't going to fix it anytime soon, what with the new release coming out and the fact that there is an easy workaround and all. opinion It is my opinion, after looking at the code that generates the error, it would be a relatively simple fix. I believe that all that would be needed is in the routine that determines the data type to sort on it should ignore nulls. As it loops through the column to find the data type should it find no non-null elements, it doesn't need to sort anything. The only performance impact would be on columns that contain lots of nulls, but I would rather have my users wait a few milliseconds rather than get an error, or have my developers waste time adding sort handlers for each column in each datagrid. Also I am sure that the sort handlers have a substantial performance impact at runtime. What I am trying to say is I believe that Adobe has made a mistake in offloading a significant amount of work onto developers, and has a poorer product, when with a small effort they can solve the problem. /opinion Paul
RE: [flexcoders] Re: Sorting problem on date and numbers with null values, I think
Well, I don't see it as a shortcoming that we default to efficient sort algorithms that assume that all values are of the same type. Seems like all you need is a comparefunction for dates and one for numbers and assign the correct function to the appropriate column. Also note that if you sort with nulls for data that hasn't arrived yet, you'll probably have to re-sort as the data arrives. The collections generally wait until all data has arrived to do the sort so it doesn't have to keep resorting as data has arrived. So, you could wait for all data to arrive as well, or maybe monkey-patch the sort code to handle null. You can file an enhancement request, but I don't see it getting done in 3.0 From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of aceoohay Sent: Friday, November 30, 2007 9:13 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Sorting problem on date and numbers with null values, I think What is the workaround? The sortCompareFunction does not seem to be reasonable, since a version needs to be written for each column in each grid. This seems like a serious shortcoming... Paul --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui [EMAIL PROTECTED] wrote: THe default sort code can't handle null as it isn't a date or number From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of aceoohay Sent: Thursday, November 29, 2007 8:49 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Sorting problem on date and numbers with null values, I think When I said no values returned from the DB, I meant that the grid is populated with some records that have the values in the number/date column, and others that don't. Paul --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders% 40yahoogroups.com , aceoohay pauls@ wrote: I running flexbuilder 2.0.1, AS 3. I have a number of datagrids. In two of my grids I have date and number fields that sometimes have no values returned from the DB. When I click the heading on these columns to sort Ascending they work fine. When I click a second time (descending) I get the following error; === Error: Cannot determine comparator for SortField with name ''MyNumberDataField''. at mx.collections::SortField/::nullCompare() at mx.collections::SortField/http://www.adobe.com/2006/flex/mx/internal: http://www.adobe.com/2006/flex/mx/internal: : http://www.adobe.com/2006/flex/mx/internal:: http://www.adobe.com/2006/flex/mx/internal:: internalCompare() at mx.collections::Sort/::internalCompare() at mx.collections::Sort/findItem() at mx.collections::ListCollectionView/getItemIndex() at ::ListCollectionViewCursor/::collectionEventHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchE v entFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.collections::ListCollectionView/dispatchEvent() at mx.collections::ListCollectionView/::internalRefresh() at mx.collections::ListCollectionView/refresh() at mx.controls::DataGrid/::sortByColumn() at mx.controls::DataGrid/::headerReleaseHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchE v entFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent() at mx.controls::DataGrid/mx.controls:DataGrid::mouseUpHandler () === I am not using a sort compare function anywhere. I have other text type fields with nulls that seem to sort correctly. This seems like a bug. Any ideas? Paul
RE: [flexcoders] Re: Sorting problem on date and numbers with null values, I think
Well, you can file an enhancement request suggesting those changes. It won't make 3.0, and I'm not sure it is common enough to get into 4.0. In the same way I offer several DataGridColumn subclasses on my blog, you could certainly contribute to the community by offering a NullDataGridColumn featuring those capabilities. Subclassing DataGridColumn to have a default generic sortCompareFunction would be my recommendation for a solution today as well. If the sortCompareFunction points to a method on your subclass, your 'this' pointer is the column and you can pull information from the column to pull the right data from the rows. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of aceoohay Sent: Friday, November 30, 2007 6:28 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Sorting problem on date and numbers with null values, I think I agree that you cannot tell what type of data a null is. The sort routine(s) has no problem sorting nulls when the non-null data is string. It also works for completely null columns. I think a reasonable solution would be a new column attribute, sortDataType (values: ascii, number, date) for datagrid columns. If you wanted to go crazy, add another attribute, nullCollateOrder (values: low, high). Modifying the existing sort routines to handle nulls should be fairly trivial. This may improve performance for columns where these attributes are specified since the routine doesn't need to read data to determine the type of sort to perform. A different approach might be an attribute nvl(value), where any nulls would be converted to the value specified. Examples might be nvl (0), nvl(9), nvl(01/01/0001), or nvl(12/31/5600) I realize I must deal with the here and now, so how would you write a generic function to hande this? It is my understanding that the sortCompareFunction wants a function like mySort(obj1:Object,obj2:Object). obj1 and obj2 are two objects that represent two rows, and to access the column to compare you need to know the property such as obj1.myDate, or obj[4]. In order to write a generic routine I need to know know what column has been clicked. Paul --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui [EMAIL PROTECTED] wrote: because null can be assigned to anything is does not have a type so we can't tell by examining the data if you want to sort by date, number, etc. Where do you want nulls to appear in a sort? Could go anywhere right? That's why you'll have to write your own compare function with the null handling rules you want. I haven't tried writing a generic compare function, but I don't see why it wouldn't be possible. From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of aceoohay Sent: Friday, November 30, 2007 1:15 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Sorting problem on date and numbers with null values, I think The data is fully populated at the time the column header is clicked. However some of the cells are null. We certainly disagree on this:-) Since a null is a valid result for all data types, it seems to me that any sort algorithm should handle the universe of valid data elements for that type. Additionally there appears to be no way to write a generic sortCompareFunction handler that will handle any column from any datagrid. If this is true then the developer needs to decide what type of data is being stored in each column, can nulls ever exist in this column and then write a custom sort routine for that column. If in fact Flex cannot sort columns with nulls, and every column that could contain a null requires the developer to write a separate custom sort handler, I think that serious shortcoming is a polite way of stating the issue. Is there a way of working around this feature? Paul --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders% 40yahoogroups.com , Alex Harui aharui@ wrote: Well, I don't see it as a shortcoming that we default to efficient sort algorithms that assume that all values are of the same type. Seems like all you need is a comparefunction for dates and one for numbers and assign the correct function to the appropriate column. Also note that if you sort with nulls for data that hasn't arrived yet, you'll probably have to re-sort as the data arrives. The collections generally wait until all data has arrived to do the sort so it doesn't have to keep resorting as data has arrived. So, you could wait for all data to arrive as well, or maybe monkey- patch the sort code to handle null. You can file an enhancement request, but I don't see it getting done
RE: [flexcoders] Re: Sorting problem on date and numbers with null values, I think
because null can be assigned to anything is does not have a type so we can't tell by examining the data if you want to sort by date, number, etc. Where do you want nulls to appear in a sort? Could go anywhere right? That's why you'll have to write your own compare function with the null handling rules you want. I haven't tried writing a generic compare function, but I don't see why it wouldn't be possible. From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of aceoohay Sent: Friday, November 30, 2007 1:15 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Sorting problem on date and numbers with null values, I think The data is fully populated at the time the column header is clicked. However some of the cells are null. We certainly disagree on this:-) Since a null is a valid result for all data types, it seems to me that any sort algorithm should handle the universe of valid data elements for that type. Additionally there appears to be no way to write a generic sortCompareFunction handler that will handle any column from any datagrid. If this is true then the developer needs to decide what type of data is being stored in each column, can nulls ever exist in this column and then write a custom sort routine for that column. If in fact Flex cannot sort columns with nulls, and every column that could contain a null requires the developer to write a separate custom sort handler, I think that serious shortcoming is a polite way of stating the issue. Is there a way of working around this feature? Paul --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , Alex Harui [EMAIL PROTECTED] wrote: Well, I don't see it as a shortcoming that we default to efficient sort algorithms that assume that all values are of the same type. Seems like all you need is a comparefunction for dates and one for numbers and assign the correct function to the appropriate column. Also note that if you sort with nulls for data that hasn't arrived yet, you'll probably have to re-sort as the data arrives. The collections generally wait until all data has arrived to do the sort so it doesn't have to keep resorting as data has arrived. So, you could wait for all data to arrive as well, or maybe monkey- patch the sort code to handle null. You can file an enhancement request, but I don't see it getting done in 3.0 From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com ] On Behalf Of aceoohay Sent: Friday, November 30, 2007 9:13 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: [flexcoders] Re: Sorting problem on date and numbers with null values, I think What is the workaround? The sortCompareFunction does not seem to be reasonable, since a version needs to be written for each column in each grid. This seems like a serious shortcoming... Paul --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders% 40yahoogroups.com , Alex Harui aharui@ wrote: THe default sort code can't handle null as it isn't a date or number From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders% 40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders% 40yahoogroups.com ] On Behalf Of aceoohay Sent: Thursday, November 29, 2007 8:49 PM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders% 40yahoogroups.com Subject: [flexcoders] Re: Sorting problem on date and numbers with null values, I think When I said no values returned from the DB, I meant that the grid is populated with some records that have the values in the number/date column, and others that don't. Paul --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders%40yahoogroups.com mailto:flexcoders% 40yahoogroups.com , aceoohay pauls@ wrote: I running flexbuilder 2.0.1, AS 3. I have a number of datagrids. In two of my grids I have date and number fields that sometimes have no values returned from the DB. When I click the heading on these columns to sort Ascending they work fine. When I click a second time (descending) I get the following error; === Error: Cannot determine comparator for SortField with name ''MyNumberDataField''. at mx.collections::SortField/::nullCompare() at mx.collections::SortField/http://www.adobe.com/2006/flex/mx/internal: http://www.adobe.com/2006/flex/mx/internal: http://www.adobe.com/2006/flex/mx/internal: http://www.adobe.com/2006/flex/mx/internal: : http://www.adobe.com/2006/flex/mx
RE: [flexcoders] Re: Sorting problem on date and numbers with null values, I think
THe default sort code can't handle null as it isn't a date or number From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of aceoohay Sent: Thursday, November 29, 2007 8:49 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Sorting problem on date and numbers with null values, I think When I said no values returned from the DB, I meant that the grid is populated with some records that have the values in the number/date column, and others that don't. Paul --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , aceoohay [EMAIL PROTECTED] wrote: I running flexbuilder 2.0.1, AS 3. I have a number of datagrids. In two of my grids I have date and number fields that sometimes have no values returned from the DB. When I click the heading on these columns to sort Ascending they work fine. When I click a second time (descending) I get the following error; === Error: Cannot determine comparator for SortField with name ''MyNumberDataField''. at mx.collections::SortField/::nullCompare() at mx.collections::SortField/http://www.adobe.com/2006/flex/mx/internal:: http://www.adobe.com/2006/flex/mx/internal:: internalCompare() at mx.collections::Sort/::internalCompare() at mx.collections::Sort/findItem() at mx.collections::ListCollectionView/getItemIndex() at ::ListCollectionViewCursor/::collectionEventHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEv entFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.collections::ListCollectionView/dispatchEvent() at mx.collections::ListCollectionView/::internalRefresh() at mx.collections::ListCollectionView/refresh() at mx.controls::DataGrid/::sortByColumn() at mx.controls::DataGrid/::headerReleaseHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEv entFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent() at mx.controls::DataGrid/mx.controls:DataGrid::mouseUpHandler () === I am not using a sort compare function anywhere. I have other text type fields with nulls that seem to sort correctly. This seems like a bug. Any ideas? Paul