JQgrid - escape ':' in searchoptions (value part) - jqgrid

How to set the values for filter is explained here link text. I have two requirements.
1. the default value needs to be empty. I expect, if defaultValue is not set, the filter is empty, but that is not happening in my case.
2. How to escape ':' in my value. The character ':' and ';' are used to seperate the index and values. But, in my value string it contains a ':' (eg: searchoptions:{value:"1:'Level: 1'"} , where Level: 1 is my first value). How to escape : in the value part. I tried \ , / etc.
thanks.
Edit: Item 1 may be solved if there is no other way. I may set an additional item ALL in the values, and use it default.

You are right, it seems impossible to use any escape character to place ':' inside of value of searchoptions if you define it like a string:
searchoptions:{value:"1:'Level: 1'"}
There is another form of setting of value of searchoptions - object form, which is also described under http://www.trirand.com/jqgridwiki/doku.php?id=wiki:search_config#colmodel_options. For example you can use following syntax
searchoptions:{value:{'1:': 'Level: 1;', ':2:;': 'Level: 2;'}}
It defines a select with the texts "Level: 1;" and "Level: 2;" displayed and the corresponding values "1:" and ":2:;". It works.

I had the same issue and the only option was to use searchoptions object.
However, I had to programmatically build the list so I couldn't use define the objects.
Therefore, I decided to use build the list as an JSON string and then parse it, as shown below:
searchoptions: {
value: $.parseJSON("{" + searchSelectFormat.join(",") + "}"),
sopt: ['eq']
}
where searchSelectFormat is in the format of
'"' + data + '":"' + data + '"';
'"' + item+ '":"' + item+ '"'

Related

Changing value of existing valuelabels via Syntax

I'm currently transforming my survey results for analysis. The survey program I used (limesurvey) automatically generates value labels, but I need to change the value the labels corresponds with. SPSS sadly doesn't do that automatically with the recode command, which only changes the values but doesn't change the value labels that correspond to it (They keep pointing at the old value which doesn't have any data entries anymore).
Basically I want to change the value labels from this:
Value labels before change
to this: Value labels after (Changing the labeled Values from A1,A2,A3,A4,A5 into 1,2,3,4,5)
And I don't just want to do it for a single variable, but dozens of variables. While this can actually be accomplished by the search/replace function via the User Interface of SPSS (that's actually how I did it in the example), I would like to do this via Syntax, so I don't have to handcraft every dataset and don't risk screwing up my data with typing mistakes.
Does anyone know how it can be done with Syntax? (Or alternatively some plugin)
So I've found a solution to my problem.
I did the recodes and the relabeling with Python.
BEGIN PROGRAM PYTHON3.
import spss, spssaux, re
sDict = spssaux.VariableDict() #Get a copy of the Variable Dictionary
infotext = "Variables processed: " # begin infotext
#Iterate through all variables (in the dictionary - all variables in this case)
for var in sDict:
#Only Adress variables which are of type String and have value labels.
if spss.GetVariableType(var.index) > 0 and var.ValueLabels != {} :
infotext += spss.GetVariableName(var.index) + ', ' #Add processed variable to infotext
#Begin Value Labels and Recode commands for active variable
commandlab = 'Value Labels ' + spss.GetVariableName(var.index) + ' '
commandrecode = 'Recode ' + spss.GetVariableName(var.index) + ' '
#commandalter = 'Alter Type ' + spss.GetVariableName(var.index) + '(f2).'
#Open entry for each value of valuelabels
for key,val in var.ValueLabels.items():
newkey = re.findall(r'\d+', key)[0] #Get first number in key (value of label)
newkey = re.sub(r'0+(.+)', r'\1', newkey) #Cut leading zeros from number
#Add entry to recode and Value labels command:
commandlab = commandlab + newkey + ' ' + '"' + val + '"' + ' '
commandrecode = commandrecode + '("' + key + '"="' + newkey + '") '
#Complete commands for SPSS:
commandlab = commandlab + '.'
commandrecode = commandrecode + '.\n Execute.'
#Execute recode and relabel.
spss.Submit(commandlab)
spss.Submit(commandrecode)
#spss.Submit(commandalter)
#Print Infos
print(infotext)
print("Warning: Only Values with value labels have been recoded. Please check your dataset to make sure all entries have been affected.")
end program.
Basically this program is finding all string variables with value labels, gets the numbers from the value/key and recodes and relabels the variables. It can also automatically turn all variables numeric, but I wouldn't recommend doing that without checking all values got converted first. In my case I merged several datasets and one variable had a value without label as a result.
Does anyone know how to get the values (or frequencies) of a variable? If possible, I'd like to catch that problem by doing the recode independent of the value labels.

PowerBuilder - Error with SetFilter(string) - Expression is not valid

I have an application that generates some reports. I use some filters in data that is retrieved.
wf_gen_filtro_conceptos()
//PROBLEM---------------
dw_rp1.setfilter(string(is_filtro) + " " + "or IsNull(causa)")
//----------------------
dw_rp1.filter()
dw_rp1.sort()
dw_rp1.groupcalc()
In wf_gen_filtro_conceptos() the variable is_filtro is set up.
The problem is when I use setfilter(). I can't concatenate those strings to create the new filter. If I use one of those strings, for example, IsNull(causa) on its own, there's NO problem.
Add a line to concatenate the string before you use the SetFilter method.
Something like
ls_filterstring = is_filtro + " " + "or IsNull(causa)"
dw_rp1.setfilter(ls_filterstring)
This way you can examine what is happening with your filterstring in the debugger. If is_filtro is NULL then the entire string will be NULL.
If is_filtro is being set make sure the quote marks, if any, in the string are correct.
I suspect that is_filtro has an invalid column, or an invalid value, or is_filtro is null, or is_filtro is empty.
Initialize is_filtro to something meaningful.
This works if you want all values.
is_filtro = "(1 = 1)"
If is_filtro is empty ("")
dw_rp1.setfilter(string(is_filtro) + " " + "or IsNull(causa)")
setfilter would be effectively
dw_rp1.setfilter(" or IsNull(causa)")
If is_filtro is null
setfilter would be effectively
dw_rp1.setfilter()
Your filter needs to match the column datatype.
Suppose that causa is a string column and you intend to filter values A, B, and C.
Wrong
is_filtro = "causa in (A, B, C)"
Right
is_filtro = "causa in ('A', 'B', 'C')"
If you are combining different filter clauses you need an and between them.
Thanks everyone for answering my question.
I've tried the stuff you suggested but it's still throwing the same error..
Here is the function that set the filter up.
choose case is_filtro_ca
case ''
messagebox("Filtro", "Is filter 1")
is_filtro = ""
case '*'
messagebox("Filtro", "Is filter 2")
is_filtro = ""
case else
messagebox("Filtro", "Is filter 3")
is_filtro = "causa in (" + is_filtro_ca + ")"
End choose
This function is called when a button "Show empty lines" is pressed. I put those messages an it always prints "Is filter 2".

FoxPro convert currency to numeric

I'm using Visual FoxPro and I need to convert currency amount into numeric. The 2 columns in the table are tranamt(numeric,12,2) and tranamt2(character)
Here's my example:
tranamt2=-$710,000.99
I've tried
replace all tranamt with val(tranamt2)
and
replace all tranamt with val(strtran(tranamt2, ",",""))
both results give me zero. I know it has something to do with the negative sign but I can't figure it out. Any help is appreciated.
Try this:
replace all tranamt with VAL(STRTRAN(STRTRAN(tranamt2, "$", ""), ",", ""))
This removes the dollar sign and comma in one shot.
need to convert currency amount into numeric
tranamt(numeric,12,2) and tranamt2(character)
First of all a neither a Character Field Type nor a Numeric Field type (tranamt2) are Not a VFP Currency Field type
You may be using the value of a Character field to represent currency, but that does not make it a currency value - just a String value.
And typically when that is done, you do NOT store the Dollar Sign '$' and Comma ',' as part of the data.
Instead, you store the 'raw' value (in this case: "-710000.99") and merely format how that 'raw' value is displayed when needed.
So in your Character field you have a value of: -$710,000.99
Do you have the Dollar Sign '$' and the Comma ',' as part of the field data?
If so, to convert it to a Numeric, you will first have to eliminate those extraneous characters prior to the the conversion.
If they are not stored as part of your field value, then you can use the VAL() 'as is'.
Example:
cStr = "-710000.99" && The '$' and ',' are NOT stored as part of Character value
nStr = VAL(cStr)
?nStr
However if you have the Dollar Sign and the Comma as part of the field data itself, then you can use STRTRAN() to eliminate them during the conversion.
Example:
cStr = "-$710,000.99" && Note both '$' and ',' are part of data value
* --- Remove both '$' and ',' and convert with VAL() ---
nStr = VAL(STRTRAN(STRTRAN(cStr,",",""),"$",""))
?nStr
Maybe something like:
REPLACE tranamt WITH VAL(STRTRAN(STRTRAN(tranamt2,",",""),"$",""))
EDIT: Another alternative would be to use CHRTRAN() to remove the '$' and ','
Something like:
cRemoveChar = "$," && Characters to be removed from String
REPLACE tranamt WITH VAL(CHRTRAN(tranamt2,cRemoveChar,""))
Good Luck
A little late but I use this function call
function MoneyToDecimal
LPARAMETER tnAmount
LOCAL lnAmount
IF VARTYPE(tnAmount) = "Y"
lnAmount = VAL(STRTRAN(TRANSFORM(tnAmount), "$", ""))
ELSE
lnAmount = tnAmount
ENDIF
return lnAmount
endfunc
And can be tested with these calls:
wait wind MoneyToDecimal($112.50)
wait wind MoneyToDecimal($-112.50)
Use the built-in MTON() function to convert a currency value into a numeric value:
replace all tranamt with mton(tranamt2)

ReportViewer Expressions , character check

I'd like to know if there is a way to check if there is a comma , in the !field.Value.
I want to make these conversations:
10,5 -> 10,50
900 -> 900,00
To do that, I need to know if there is a comma in the field value and also how many characters are after the comma. Is it possible ?
Look at InStr(), Len(), and IIF(), I think they will get you what you want.
I don't have a way to test this where I am, but basically I think this expression will get you there:
=IIF(InStr(Fields!MyField.Value, ",") > 0,
Fields!MyField.Value & LEFT("000000", (-1 *(2 - (Len(Fields!MyField.Value) - InStr(Fields!MyField.Value, ","))))),
Fields!MyField.Value & ",00")
Here's the basic idea of the script:
If there is a comma in the field,
then add x number of 0s onto the end of the field
where x is 2 - (the length of the field - the position of the ',' in the string) * -1
else just return the field + ",00"

XPath 2.0:reference earlier context in another part of the XPath expression

in an XPath I would like to focus on certain elements and analyse them:
...
<field>aaa</field>
...
<field>bbb</field>
...
<field>aaa (1)</field>
...
<field>aaa (2)</field>
...
<field>ccc</field>
...
<field>ddd (7)</field>
I want to find the elements who's text content (apart from a possible enumeration, are unique. In the aboce example that would be bbb, ccc and ddd.
The following XPath gives me the unique values:
distinct-values(//field[matches(normalize-space(.), ' \([0-9]\)$')]/substring-before(., '(')))
Now I would like to extent that and perform another XPath on all the distinct values, that would be to count how many field start with either of them and retreive the ones who's count is bigger than 1.
These could be a field content that is equal to that particular value, or it starts witrh that value and is followed by " (". The problem is that in the second part of that XPath I would have refer to the context of that part itself and to the former context at the same time.
In the following XPath I will - instead of using "." as the context- use c_outer and c_inner:
distinct-values(//field[matches(normalize-space(.), ' \([0-9]\)$')]/substring-before(., '(')))[count(//field[(c_inner = c_outer) or starts-with(c_inner, concat(c_outer, ' ('))]) > 1]
I can't use "." for both for obvious reasons. But how could I reference a particular, or the current distinct value from the outer expression within the inner expression?
Would that even be possible?
XQuery can do it e.g.
for $s
in distinct-values(
//field[matches(normalize-space(.), ' \([0-9]\)$')]/substring-before(., '(')))
where count(//field[(. = $s) or starts-with(., concat($s, ' ('))]) > 1
return $s

Resources