PDA

View Full Version : Replication??


afriedrichs
04-05-2007, 09:35 AM
I have a xml dataset... what we want to do is use the dataset for 2 differnt combo boxes, one sorted by say employee name and the other by employee number. From what I been reading, I should be able to pull this off by replicating the dataset and sorting as needed. But I don't know how to do this. The more I read the more confused I get. I was hoping that someone could get me some code to get me started based on my employee example.

My dataset has 3 fields: employee name, employee number, and a field with number and name strung together.

I'm sorting it originally by employee number, so I figure I just need to replicate it and sort by name and use this one in my name combo box.

I've seen the code for sorting and such, but haven't found much that actually gives me good info on the replication part of it.

Help Please!!! (Newbie ?, I'm sure since everyone seems to be using it!) Thanks in advance for any help!

senshi
04-07-2007, 03:38 AM
Basic OpenLaszlo-Sorting for replicated views compares Strings, for Numbers I've taken two functions from "basegridcolumn":


<canvas debug="true" >

<dataset name="ds" >
<employees>
<employee name="John Doe" number="1" all="John_Doe_1" />
<employee name="Max Mustermann" number="0" all="Max_Mustermann_0" />
<employee name="Princess Fiona" number="3" all="Princess_Fiona_3" />
<employee name="Shrek" number="2" all="Shrek_2" />
</employees>
</dataset>

<script>
<![CDATA[
//@see basegridcolumn#_numericAscendingSort(..)
_numericAscendingSort = function(a,b){
var x = Number( a );
var y = Number( b );

//if a variable is NaN, then it won't equal itself
var xisnum = x == x;
var yisnum = y == y;

if ( xisnum == yisnum ){
if ( !xisnum ){
x = a;
y = b;
}
if ( x < y ){
return 1;
} else if ( x == y ){
return 0;
} else {
return -1;
}
} else if ( xisnum ){
return 1;
} else {
return -1;
}
}

//@see basegridcolumn#_numericDescendingSort(..)
_numericDescendingSort = function(a,b){
var x = Number( a );
var y = Number( b );

//if a variable is NaN, then it won't equal itself
var xisnum = x == x;
var yisnum = y == y;

if ( xisnum == yisnum ){
if ( !xisnum ){
x = a;
y = b;
}
if ( x > y ){
return 1;
} else if ( x == y ){
return 0;
} else {
return -1;
}
} else if ( yisnum ){
return 1;
} else {
return -1;
}
}
]]>
</script>

<simplelayout axis="x" spacing="10" inset="15" />

<combobox datapath="ds:/employees" editable="false" >
<textlistitem text="$path{'@name'}" >
<datapath xpath="employee" sortpath="@name" sortorder="ascending" />
</textlistitem>
</combobox>

<combobox datapath="ds:/employees" editable="false" >
<textlistitem text="$path{'@name'}" >
<datapath xpath="employee" sortpath="@name" sortorder="descending" />
</textlistitem>
</combobox>

<combobox datapath="ds:/employees" editable="false" >
<textlistitem text="$path{'@number'}" >
<datapath xpath="employee" sortpath="@number" sortorder="ascending" >
<method name="init" >
var func;
if( this.sortorder == "ascending" ){
func = _numericAscendingSort;
} else {
func = _numericDescendingSort;
}
this.setOrder( this.sortpath, func );
super.init();
</method>
</datapath>
</textlistitem>
</combobox>

<combobox datapath="ds:/employees" editable="false" >
<textlistitem text="$path{'@number'}" >
<datapath xpath="employee" sortpath="@number" sortorder="descending" >
<method name="init" >
var func;
if( this.sortorder == "ascending" ){
func = _numericAscendingSort;
} else {
func = _numericDescendingSort;
}
this.setOrder( this.sortpath, func );
super.init();
</method>
</datapath>
</textlistitem>
</combobox>

</canvas>

afriedrichs
04-12-2007, 06:06 AM
Thanks for the great example! It was almost too easy! Amazing how a full example in context can make a huge difference! Thank you for taking the time to do that! Worked wonderfully!