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 1000000) 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.com<mailto: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 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