Re: Sorting Columns

2015-03-04 Thread ha...@exformedia.se

There is a lession on how to format your display here:

http://lessons.runrev.com/m/datagrid/l/7327-how-do-i-override-the-default-behavior-for-rendering-data-to-a-cell

In short you need to override the default behavior of the datagrid column:

1. Create a new button and select it
2. Copy the default behavior script to your button via:
set the script of the selectedobject to the script of button 
Default Column of stack revDataGridLibrary

3. Tell the datagrid to use your behavior instead via:
   set the dgProps[default column behavior] of group Your data grid 
to the long id of the selectedObject

4. Edit the script of your button

What you need look for is the fillInData function

Let say you want to display your big sales number as $ 1.000.000 (but 
still have the value saved as 100) you can change fillInData to


on FillInData pData
   set the text of me to formatNumber(pData, ,, ., $ )
end FillInData

Then you only need to add the formatNumber function...

function formatNumber pNum, pSeparator, pCommaSign, pPrefix, pPostfix
   local tIsNegative, tRest, tCommaPos
   if pNum  0 then
  put abs(pNum) into pNum
  put true into tIsNegative
   end if
   put offset(pCommaSign, pNum) into tCommaPos
   if tCommaPos  0 then
  put char tCommaPos to -1 of pNum into tRest
   end if
   put char 1 to tCommaPos -1 of pNum into pNum
   repeat with i = length(pNum)-3 to 3 step -3
  put pSeparator before char i+1 of pNum
   end repeat
   if tIsNegative then
  return pPrefix  -   pNum  tRest  pPostfix
   else
  return pPrefix  pNum  tRest  pPostfix
   end if
end formatNumber

Finally if you just want to target a specific column for your formatting 
you can use the dgColumn property (or dgColumnNumber) to ensure you only 
format specific columns


Let's say you have a column named Value that you would like to format 
but no other columns you can change fillInData to:


on FillInData pData
   put the dgColumn of me into tCol
   if tCol is Value then
  set the text of me to formatNumber(pData,  , ., $ )
   else
  set the text of me to pData
   end if
end FillInData

Happy Coding!

:-Håkan


Bob Sneidar mailto:bobsnei...@iotecdigital.com
4 mars 2015 01:13
dgData returns an array. dgText returns delimited text. if the commas 
are thousand delimiters, then strip them. I’ve often thought of trying 
to implement a “displayAs functionality for Datagrids, like Excel 
does, where the value is one thing but the display is another. Your 
situation really underscores the need for this.


Bob S


On Mar 3, 2015, at 06:18 , dunb...@aol.commailto:dunb...@aol.com wrote:

An easy way is to extract the full dataset, perhaps with the dgData. 
This will give you a tab and return delimited list. Then you might 
sort by a function:


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode
dunb...@aol.com mailto:dunb...@aol.com
3 mars 2015 15:18
An easy way is to extract the full dataset, perhaps with the dgData. 
This will give you a tab and return delimited list. Then you might 
sort by a function:



sort yourData numeric by goodNumber(item columnOfInterest of each)


where:


function goodNumber var
repeat for each char tChar in var
if var is in 0123456789 then put tChar after temp
end repeat
return temp
end goodNumber


Craig Newman



-Original Message-
From: JB sund...@pacifier.com
To: How to use LiveCode use-livecode@lists.runrev.com
Sent: Tue, Mar 3, 2015 6:33 am
Subject: Sorting Columns


I have a data grid and one of the columns
has numbers with commas included. If I
use the property inspector and select the
header column I can choose sort by text
or numeric. Due to the commas neither
of the sort types gives me a correct sort.

Do I need to make another array and strip
the commas and then use that sort with
columns from the original array? What is
the best way to sort numeric columns with
commas included in the numbers?

John Balgenort

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription

preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode

JB mailto:sund...@pacifier.com
3 mars 2015 12:30
I have a data grid and one of the columns
has numbers with commas included. If I
use the property inspector and select the
header column I can choose sort by text
or numeric. Due to the commas neither
of the sort types gives me a correct sort.

Do I need to make another array and strip
the commas and then use that sort

Re: Sorting Columns

2015-03-04 Thread JB
:-Håkan,

Thank you for the link, the code
and instructions.

It will help a lot!

And thank you again to everyone
who replied.  It all helps me very
much and I really appreciate it.

John Balgenorth


On Mar 4, 2015, at 2:56 AM, ha...@exformedia.se wrote:

 There is a lession on how to format your display here:
 
 http://lessons.runrev.com/m/datagrid/l/7327-how-do-i-override-the-default-behavior-for-rendering-data-to-a-cell
 
 In short you need to override the default behavior of the datagrid column:
 
 1. Create a new button and select it
 2. Copy the default behavior script to your button via:
set the script of the selectedobject to the script of button Default 
 Column of stack revDataGridLibrary
 3. Tell the datagrid to use your behavior instead via:
   set the dgProps[default column behavior] of group Your data grid to the 
 long id of the selectedObject
 4. Edit the script of your button
 
 What you need look for is the fillInData function
 
 Let say you want to display your big sales number as $ 1.000.000 (but still 
 have the value saved as 100) you can change fillInData to
 
 on FillInData pData
   set the text of me to formatNumber(pData, ,, ., $ )
 end FillInData
 
 Then you only need to add the formatNumber function...
 
 function formatNumber pNum, pSeparator, pCommaSign, pPrefix, pPostfix
   local tIsNegative, tRest, tCommaPos
   if pNum  0 then
  put abs(pNum) into pNum
  put true into tIsNegative
   end if
   put offset(pCommaSign, pNum) into tCommaPos
   if tCommaPos  0 then
  put char tCommaPos to -1 of pNum into tRest
   end if
   put char 1 to tCommaPos -1 of pNum into pNum
   repeat with i = length(pNum)-3 to 3 step -3
  put pSeparator before char i+1 of pNum
   end repeat
   if tIsNegative then
  return pPrefix  -   pNum  tRest  pPostfix
   else
  return pPrefix  pNum  tRest  pPostfix
   end if
 end formatNumber
 
 Finally if you just want to target a specific column for your formatting you 
 can use the dgColumn property (or dgColumnNumber) to ensure you only format 
 specific columns
 
 Let's say you have a column named Value that you would like to format but 
 no other columns you can change fillInData to:
 
 on FillInData pData
   put the dgColumn of me into tCol
   if tCol is Value then
  set the text of me to formatNumber(pData,  , ., $ )
   else
  set the text of me to pData
   end if
 end FillInData
 
 Happy Coding!
 
 :-Håkan
 
 Bob Sneidar mailto:bobsnei...@iotecdigital.com
 4 mars 2015 01:13
 dgData returns an array. dgText returns delimited text. if the commas are 
 thousand delimiters, then strip them. I’ve often thought of trying to 
 implement a “displayAs functionality for Datagrids, like Excel does, where 
 the value is one thing but the display is another. Your situation really 
 underscores the need for this.
 
 Bob S
 
 
 On Mar 3, 2015, at 06:18 , dunb...@aol.commailto:dunb...@aol.com wrote:
 
 An easy way is to extract the full dataset, perhaps with the dgData. This 
 will give you a tab and return delimited list. Then you might sort by a 
 function:
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 dunb...@aol.com mailto:dunb...@aol.com
 3 mars 2015 15:18
 An easy way is to extract the full dataset, perhaps with the dgData. This 
 will give you a tab and return delimited list. Then you might sort by a 
 function:
 
 
 sort yourData numeric by goodNumber(item columnOfInterest of each)
 
 
 where:
 
 
 function goodNumber var
 repeat for each char tChar in var
 if var is in 0123456789 then put tChar after temp
 end repeat
 return temp
 end goodNumber
 
 
 Craig Newman
 
 
 
 -Original Message-
 From: JB sund...@pacifier.com
 To: How to use LiveCode use-livecode@lists.runrev.com
 Sent: Tue, Mar 3, 2015 6:33 am
 Subject: Sorting Columns
 
 
 I have a data grid and one of the columns
 has numbers with commas included. If I
 use the property inspector and select the
 header column I can choose sort by text
 or numeric. Due to the commas neither
 of the sort types gives me a correct sort.
 
 Do I need to make another array and strip
 the commas and then use that sort with
 columns from the original array? What is
 the best way to sort numeric columns with
 commas included in the numbers?
 
 John Balgenort
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 JB

Re: Sorting Columns

2015-03-03 Thread Sri
dunbarx wrote
 An easy way is to extract the full dataset, perhaps with the dgData.
 This will give you a tab and return delimited list. 

1. I think Craig meant dgText (dgData is an array).

2. Don't forget to set itemDel to tab

Regards,
Sri.



--
View this message in context: 
http://runtime-revolution.278305.n4.nabble.com/Sorting-Columns-tp4689614p4689631.html
Sent from the Revolution - User mailing list archive at Nabble.com.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sorting Columns

2015-03-03 Thread dunbarx
Sri is right about all that. I could surely have been more helpful about the
difference between dgData and dgText.

I assumed that tab and return delimited data implied a tab delim.

All good, though.

Craig



--
View this message in context: 
http://runtime-revolution.278305.n4.nabble.com/Sorting-Columns-tp4689614p4689636.html
Sent from the Revolution - User mailing list archive at Nabble.com.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sorting Columns

2015-03-03 Thread Geoff Canyon
On Tue, Mar 3, 2015 at 8:18 AM, dunb...@aol.com wrote:

 function goodNumber var
   repeat for each char tChar in var
 if var is in 0123456789 then put tChar after temp
   end repeat
   return temp
 end goodNumber


It's worth checking, but this might be faster (but less robust):

function goodNumber var
  replace comma with empty in var
  return var
end goodNumber

if that does work, then I'd replace it with a more general function:

function replaceF S,F,R
  replace F with R in S
  return S
end replaceF

and then call it with

sort yourData numeric by replaceF(item columnOfInterest of each,comma,empty)
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sorting Columns

2015-03-03 Thread JB
Thanks Bob!

Any explanation is helpful since
I am fairly new to data grids.

The commas are thousands delimiters.

John Balgenorth


On Mar 3, 2015, at 4:13 PM, Bob Sneidar bobsnei...@iotecdigital.com wrote:

 dgData returns an array. dgText returns delimited text. if the commas are 
 thousand delimiters, then strip them. I’ve often thought of trying to 
 implement a “displayAs functionality for Datagrids, like Excel does, where 
 the value is one thing but the display is another. Your situation really 
 underscores the need for this.
 
 Bob S
 
 
 On Mar 3, 2015, at 06:18 , dunb...@aol.commailto:dunb...@aol.com wrote:
 
 An easy way is to extract the full dataset, perhaps with the dgData. This 
 will give you a tab and return delimited list. Then you might sort by a 
 function:
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sorting Columns

2015-03-03 Thread JB
Thank you, for the info and code.

John Balgenorth


On Mar 3, 2015, at 2:16 PM, Geoff Canyon gcan...@gmail.com wrote:

 On Tue, Mar 3, 2015 at 8:18 AM, dunb...@aol.com wrote:
 
 function goodNumber var
  repeat for each char tChar in var
if var is in 0123456789 then put tChar after temp
  end repeat
  return temp
 end goodNumber
 
 
 It's worth checking, but this might be faster (but less robust):
 
 function goodNumber var
  replace comma with empty in var
  return var
 end goodNumber
 
 if that does work, then I'd replace it with a more general function:
 
 function replaceF S,F,R
  replace F with R in S
  return S
 end replaceF
 
 and then call it with
 
 sort yourData numeric by replaceF(item columnOfInterest of each,comma,empty)
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sorting Columns

2015-03-03 Thread Bob Sneidar
dgData returns an array. dgText returns delimited text. if the commas are 
thousand delimiters, then strip them. I’ve often thought of trying to implement 
a “displayAs functionality for Datagrids, like Excel does, where the value is 
one thing but the display is another. Your situation really underscores the 
need for this.

Bob S


On Mar 3, 2015, at 06:18 , dunb...@aol.commailto:dunb...@aol.com wrote:

An easy way is to extract the full dataset, perhaps with the dgData. This 
will give you a tab and return delimited list. Then you might sort by a 
function:

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Sorting Columns

2015-03-03 Thread JB
Thanks for the info, Srl.

John Balgenorth


On Mar 3, 2015, at 11:30 AM, Sri sri...@gmail.com wrote:

 dunbarx wrote
 An easy way is to extract the full dataset, perhaps with the dgData.
 This will give you a tab and return delimited list. 
 
 1. I think Craig meant dgText (dgData is an array).
 
 2. Don't forget to set itemDel to tab
 
 Regards,
 Sri.
 
 
 
 --
 View this message in context: 
 http://runtime-revolution.278305.n4.nabble.com/Sorting-Columns-tp4689614p4689631.html
 Sent from the Revolution - User mailing list archive at Nabble.com.
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sorting Columns

2015-03-03 Thread dunbarx
An easy way is to extract the full dataset, perhaps with the dgData. This 
will give you a tab and return delimited list. Then you might sort by a 
function:


sort yourData numeric by goodNumber(item columnOfInterest of each)


where:


function goodNumber var
  repeat for each char tChar in var
if var is in 0123456789 then put tChar after temp
  end repeat
  return temp
end goodNumber


Craig Newman



-Original Message-
From: JB sund...@pacifier.com
To: How to use LiveCode use-livecode@lists.runrev.com
Sent: Tue, Mar 3, 2015 6:33 am
Subject: Sorting Columns


I have a data grid and one of the columns
has numbers with commas included.  If I
use the property  inspector and select the
header column I can choose sort by text
or numeric.  Due to the commas neither
of the sort types gives me a correct sort.

Do I need to make another array and strip
the commas and then use that sort with
columns from the original array?  What is
the best way to sort numeric columns with
commas included in the numbers?

John Balgenort

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Sorting Columns

2015-03-03 Thread JB
I have a data grid and one of the columns
has numbers with commas included.  If I
use the property  inspector and select the
header column I can choose sort by text
or numeric.  Due to the commas neither
of the sort types gives me a correct sort.

Do I need to make another array and strip
the commas and then use that sort with
columns from the original array?  What is
the best way to sort numeric columns with
commas included in the numbers?

John Balgenort

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sorting Columns

2015-03-03 Thread JB
Thank you very much, Craig!

John Balgenorth


On Mar 3, 2015, at 6:18 AM, dunb...@aol.com wrote:

 An easy way is to extract the full dataset, perhaps with the dgData. This 
 will give you a tab and return delimited list. Then you might sort by a 
 function:
 
 
 sort yourData numeric by goodNumber(item columnOfInterest of each)
 
 
 where:
 
 
 function goodNumber var
  repeat for each char tChar in var
if var is in 0123456789 then put tChar after temp
  end repeat
  return temp
 end goodNumber
 
 
 Craig Newman
 
 
 
 -Original Message-
 From: JB sund...@pacifier.com
 To: How to use LiveCode use-livecode@lists.runrev.com
 Sent: Tue, Mar 3, 2015 6:33 am
 Subject: Sorting Columns
 
 
 I have a data grid and one of the columns
 has numbers with commas included.  If I
 use the property  inspector and select the
 header column I can choose sort by text
 or numeric.  Due to the commas neither
 of the sort types gives me a correct sort.
 
 Do I need to make another array and strip
 the commas and then use that sort with
 columns from the original array?  What is
 the best way to sort numeric columns with
 commas included in the numbers?
 
 John Balgenort
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode