I had a jqgrid with float numbers. I tried to get rid of the right side 0 and group the numbers, so those are now like (for example: "123,242"), and you know that the type of them are now String.
I want to sort theme like integer numbers in jqgrid.
what should I do?
for example a part of a column
after sort(asc) these strings are like
this:
1,959
1,965
1,989
10,235
100
100
...
Thanks in advance.
I believe you implemented the indexing and sorting according to jqGrid document. For example: http://www.trirand.net/forum/default.aspx?g=posts&t=254
I assume you retrieved data from database. If you’ve followed those already, moreover, you may need to CAST or CONVERT that particular database field from STRING or VARCHAR into INT or NUMERIC when you bind your SQL query.
jqGrid is powerful to do rest of things automatically.
You can zero-pad them (e.g. 00100 and 01959), sort them, and then remove the padding. Computer Programming 0101.
Related
I am currently re-educating myself on Google sheets and I was wondering if there was a way to sort a set of numbers by string to deal with tiebreakers (i.e. a win/loss/tie record)
Using the SORT function, I was able to sort things correctly based on wins, but I want to be able to adjust it even further. Currently I have something like this...
3-0-0
1-4-0
1-3-0
1-2-0
1-1-0
when I want to have something like this, where the values with the lowest loss record goes on top instead...
3-0-0
1-1-0
1-2-0
1-3-0
1-4-0
Is there another function or a workaround possible to achieve something like this?
=SORT(A1:A5,INDEX(SPLIT(A1:A5,"-"),,1),0,INDEX(SPLIT(A1:A5,"-"),,2),1)
SPLIT(A1:A5,"-") by -
INDEX(SPLIT(A1:A5,"-"),,1) get first column of the split array
INDEX(SPLIT(A1:A5,"-"),,2) get second column
=SORT(A1:A5,col1,0,col2,1) Sort A1:A5 in descending order based on column1 and ascending order based on column 2
While in "human language" something like 3-0-0 could be called "a set of numbers" in "spreadsheet language" it's a text value.
To be able to use the built-in sorting functions in Google Sheets, you should split the values into columns, and guess what, there is a built-in function for that:
Select the column
Click on Data > Split text to columns
Select custom separarator and set -
There are a more options, like using a formulas and scripts.
Sample formula
=ArrayFormula(QUERY(
{A1:A5,REGEXEXTRACT(A1:A5,"-(\d{1,})-")},
"select Col1 order by Col2",0)
)
The above formula use a regular expression to extract the numbers between -, then use QUERY to sorth the values in A1:A5 in ascending order by using these values.
I am trying to create an appropriate Format table property of a specific MS Access table in order to achieve the display style described below. For example purposes, let the table name be example and the field that I am trying to format be dollars
When example!dollars.Value is 567.98, I wish to display $0.567K. I also wish to display 1,000.42 as $1.000K.
In another table storing larger values, I use the Format property string $#,##0,\K; ($#,##0,"K)"[Red];"| < $1K |"; --, which successfully displays the amount in K dollars; however, any values less than $1K cannot be displayed. This is not acceptable due to the scale of the values in the example table.
The most intuitive solution is to use the string $0,000\K and specify the thousands separator as . instead of ,. However, I do not know how to do this.
Any advice will be greatly appreciated!
This works for me:
Kamount = Format(Amount/1000, "$0.000K")
So divide by 1000, then format as needed.
Use the Format property string $0\.000\K
I had a need to output TCURR table into ALV grid. All went fine but when user sorts table by "valid from" date (GDATU) strange things happened.
Sorting in ascending order behaves as sorting in descending order and vice versa. This is so because field GDATU contains date in inverted format and has domain GDATU_INV with the conversion routine INVDT which converts date on the fly. ALV grid shows the date correctly but sorting is done by inverted dates.
I solved it like this:
I declared table structure similar to TCURR and replaced GDATU_INV domain with simple DATUM.
I converted inverted dates into usual ones
I filled my table with the converted dates
After generating field catalog through FM LVC_FIELDCATALOG_MERGE according to TCURR structure I write to
CONVEXIT,
REF_TABLE,
DATATYPE,
DOMNAME
fields of the GDATU line values
'',
'',
'DATS',
'DATUM' respectively.
Is there more efficient and simple solution to this problem?
You should be able to use your new structure in LVC_FIELDCATALOG_MERGE, in stead of using TCURR which would mean that you don't have to overwrite the settings in the field catalog after the fact. But that's a pretty minor thing.
I don't think you had any choice but to use a structure with a data element that behaves the way you need it to.
Do look into the Simple ALV classes, though. (CL_SALV*) They are well documented and much easier to use than then now out-of-date ALV function modules. (Particularly generating the field catalog is a lot less hassle).
I have a pivot collection that has a numeric facet, however when the value is being displayed it keeps rounding to the nearest whole number.
Is there a way in which I can show the full number with the decimal places?
I am assuming that you are talking in CXML? If so, there is a Format attribute you can set on the facet category. It only works for DateTime and Numeric, but that will work in your case. The accepted format strings are .NET format strings.
Check here for full documentation of the PivotViewer CXML Schema
just wondering does anyone in here have good idea about generating nice order id?
for example
832-28-394, which show a quite nice and formal order id (rather than just use an database auto increment number like ID=35).
the order id need to look random so it can not be able to guess by user.
e.g. 832-28-395 (shoudnt exist) so there will always some gap between each id.
just like the account number for your bank card?
Cheers
If you are using .NET you can use System.Guid.NewGuid()
The auto-incremented IDs are stored as integer or long integer data. One of the reasons for this is that this format is compact, saving space, including in indexes which are typically inclusive a primary key for use with joins and such.
If you wish to create a nice looking id following a particular format syntax, you'll need to manage the generation of the IDs yourself, and store these in a "regular" column not one that is auto-incremented.
I suggest you keep using "ugly looking" ids, be they auto-incremented or not, and format these value for display purposes only, using whatever format you may desire, including some format that use the values from several columns. Depending on the database system you are using you may be able to declare custom functions, at the level of the database itself, allowing you to obtain the readily formatted value with a simple query (as in
SELECT MakeAFancyId(id_field), some_other_columns, ..
FROM ...
If you cannot use some built-in or custom function at the level of SQL, you'll need to format the value supplied by SQL (an integer of sorts), into the desired format, on the client-side, using the language associated with your UI / presentation framework.
I'd create something where the first eight numbers are loosely in a pattern, and a third quartet looks random but is really a sort of checksum.
So, for example, the first eight digits increment based on the current seconds on the server clock.
The last four could be something like the sum of the first four, plus twice the sum of the second four, which will give either a two or three digit number. The final digit is calculated so that the sum of all 11 digits plus this last one is a multiple of 9.
This is slightly akin to how barcode numbers are verified. You can format the resulting 12 digits any way you want, although it is the first eight that are unique here.
Hash the clock time.
Mod by 100,000 or something.
Format with hyphens.
Check for duplicates. If found, restart.
I would suggest using a autoincrement ID in the database to link tables and as a primary key. Integer fields are always faster than string fields for indexing and well as searching.
You can have the order number field (which is for display) as a different field in the order table which will be used to display. And whenever you are planning to send a URl to a user or display a URL to the user which has order ID (which is a autoincremented number) you can encrypt it with some algorithm.
Both your purpose will be solved.
But I suggest not to make string as primary key. Though you can have a unique constraint on the order number which is going to be displayed.
Hope this helps.
Kalpak Luniya
I would suggest internally you keep the database derived primary key, which is auto-incremented.
For the visible order number, you will probably need a longer length than 8 characters, if you are using this for security.
If you are using Ruby, look at SecureRandom, which will generate sufficiently random strings to accomodate this. For example, you can use SecureRandom.hex(16), and it will give you a 16 digit hex number. I believe it can also give you base 64 strings, which will look weirder but be shorter.
Make sure this is not your only security on an order, as it may not be that hard to find a valid order number within your 8 digit code, especially if some are some sort of checksum.
For security reasons i suggest that you should use Criptographicaly secure random number generator. Think about idea on icreasing User Id length -if you have 1 million users then the probability to gues User ID in first try is 0.01 and 67 tries to increase probability over 0.5