JqGrid Blank value in dropdown List - jqgrid

I want to show a blank value in dropdown list , i am using the code like this , but this make a dropdownlist in which blank value comes at last , and by default selected , i want blank value at first and by default selected
{name: 'AuditLevel', index: 'levels', align: 'center', width: 15,
editable: true, edittype: 'select',
editoptions: { value: {' ': ' ',1: 'Level1', 2: 'Level2', 3: 'Level3' }}
Any Solution for this

The problem exists because you use object form of editoptions.value. The only way to read such editoptions.value object in JavaScript is enumeration of properties of the object (with loop like var prop; for (prop in editoptions.value)). The problem is that the order of the properties in the case could be not the same as the order in which you wrote the properties during initialization of the object.
So you should use string form if the order of the properties are important for you:
editoptions: { value: " : ;1:Level1;2:Level2:3:Level3" }
would be better as
editoptions: { value: {' ': ' ',1: 'Level1', 2: 'Level2', 3: 'Level3' }
jqGrid will split the string " : ;1:Level1;2:Level2:3:Level3" by ; and then it will use : as the separator between the value and the text of options. If the text (or the value) of the options contains the separators : or ; you can use another separators, but you have to inform using separator (it's default value is ":") and delimiter property (it's default value is ";"). For example
editoptions: {
value: " ↣ |1↣Level1|2↣Level;2|3↣Level:3"
delimiter: "|",
separator: "↣"
}

Related

jqgrid reading form element value and dynamically changing select option

I like to change the Type field drop down option depending on the inputs of Year and Level fields.
I am able to trigger an event when Level is change.
But how do I get the value of the Year field?
Portion of the code are as follows
colModel:[
{name:'Year',index:'Year', width:70,sortable:false,editable:true,align:'center',editoptions:{size:15, maxlength:4}, formoptions:{ rowpos:1, label: "Year (*)"},editrules:{required:true}},
{name:'Level',index:'Level', width:70,sortable:false,editable:true,align:'center',edittype: "select", editoptions: { value: '1:1;2:2;3:3;4:4;5:5;6:6', defaultValue:'1', dataEvents : [
{
'type' : 'change',
'fn' : function ( el ) {
// get the newly selected value from the user
var levelz = $(el.target).val(), yearz ;
var row = $(el.target).closest('tr.jqgrow');
var rowid = row.attr('id');
//yearz = ??
if (parseInt(levelz)==5 || parseInt(levelz)==6)
{
if (parseInt(yearz)>2017)
{
$("#gridmain").jqGrid('setColProp','Term', {editoptions: { value: '1:Sem 1;4:Sem 2;6:EY;9:OVR', defaultValue:'Sem 1'}} );
}else{
$("#gridmain").jqGrid('setColProp','Term', {editoptions: { value: '', defaultValue:''}} );
}
}else{
$("#gridmain").jqGrid('setColProp','Term', {editoptions: { value: '1:TA1/CT1;2:TA2-before 2013;3:MY/TA2/CT2;4:TA3/CT3;5:TA4-before 2013;6:EY/TA4/CT4;9:OVR;D:CW1;E:CW2;F:CW3;G:CW4', defaultValue:'TA1'}} );
}
}
}]}, formoptions:{ rowpos:2, label: "Level (*)"},editrules:{required:true}},
{name:'Term',index:'Term', width:70, sortable:false,editable: true,align:'center',edittype: "select", editoptions: { value: '1:TA1/CT1;2:TA2-before 2013;3:MY/TA2/CT2;4:TA3/CT3;5:TA4-before 2013;6:EY/TA4/CT4;9:OVR;D:CW1;E:CW2;F:CW3;G:CW4', defaultValue:'TA1'}, editrules: { required: true }, formoptions:{ rowpos:3, label: "Type"}},
The codes are from piecing together what I read from google search...
I face 2 issues:
1) I don't know how to get the Year value
2) The drop down option list doesn't seems to change. - hmm it seems that if I close the edit form and open again, the Type field drop down option changes. What I need is to change the option on the fly - wonder how this can be done...
After much googling, managed to get the ans from Oleg's post as shown here
Also from his example, I derive the year value:
var yearz = $("#Year.FormElement", form[0]).val();

jqgrid number formatter with separator and scale values

Using the number formatter like below to format the JQgrid number with decimalSeparator(,)& decimalPlaces(2)
formatter: 'number', formatoptions :{decimalSeparator: ',', decimalPlaces:2}
after enter the value as 134,56 in grid it was showing as 'NaN'.
please help me how to resolve this issue.
The easy way to display correct the number in case you save to database is to set reloadAfterSubmit to true in navigator or in editGridRow method like this
$("#jqGrid").navGrid("#jqGridPager",{ edit: true, add: true },
// edit options
{ reloadAfterSubmit : true },
// add options
{ reloadAfterSubmit : true }
);

jqgrid editable x number formating is inconsisent with format on grid

I've built a grid as the code bellow:
colModel: [
{ name: 'price',
label: 'price',
index: 'price',
jsonmap: 'price',
formatter: 'number',
formatoptions: {decimalSeparator:",", thousandsSeparator: ".", decimalPlaces: 2, defaultValue: '0,00'},
editable: true
}
]
The format of field is correctly on grid, for instance: 10,32, but the form created to edit the field fills one with 10.32 instead of 10,32.
Someone knows why this is going on? Do I need to use properties as edittype and editoptions (this one using formmater and formatoptions) as well? if yes, How I need set up these properties?
I've fixed the problem using the the function afterShowForm to handle the formating of field on form generated from grid.
In fact, I was expecting that jQGrid could do that automatically, i.e, using the configuration provided to column to apply on field generated, or if i could apply the configurion on JSON message, for instance:
editoptons: { formatter = "number", formatteroptions = { .... } ...
anyway, it's working now.

Currency Mask jqgrid

I am new to jqGrid, and having trouble with achieving a couple of tasks. Any guidance will be a huge help.
Issue1# I need to perform following jquery masking on my rate field in the create form,
$('#Rate').priceFormat({ prefix: '', thousandsSeparator: '' }); How could I achieve this in jqGrid?
Thanks a lot.
This is what I have right now:
JQGridColumn RATEColumn = CapitationsGrid.Columns.Find(c => c.DataField == "RATE");
RATEColumn.Editable = true;
RATEColumn.EditType = EditType.TextBox;
RATEColumn.EditDialogLabel = "Rate";
RATEColumn.DataType = typeof(float);
RATEColumn.EditClientSideValidators.Add(new RequiredValidator());
RATEColumn.EditClientSideValidators.Add(new NumberValidator());
RATEColumn.Formatter = new CurrencyFormatter
{
DecimalPlaces = 1,
DecimalSeparator = ".",
Prefix = "$",
Suffix = " USD",
ThousandsSeparator = ","
};
It's important to understand, that jqGrid try to separate the data from the visualization. So If you need to display currency for example you should fill numbers in the input data and use predefined of custom formatters to display the currency in format which corresponds the locale which you need.
To format currency you should use formatter: 'currency', formatoptions: {thousandsSeparator: ""} (see the documentation). The default values of formatoptions of the currency formatter you will find in the locale file like grid.locale-en.js which you use.
This covers your problem. Have a look.
name: 'Currency',
width: 75,
formatter: 'currency',
formatoptions: { decimalSeparator: '.', decimalPlaces: 1, suffix: ' USD', thousandsSeparator: ',', prefix: '$' }
http://www.guriddo.net/demo/guriddojs/functionality/formatters_built_in/index.html

jQGrid checkbox values

I have an editable checkbox in my jQGrid with the values
editoptions: { value: "Yes:No" }
But whatever the value is i am getting back on controller string value "Yes:No", not single value "Yes" of "No", so i am getting it like that:
When it is checked i am getting this:
form["MyCheckBox"] = "Yes:No".
When it is not checked i am getting this:
form["MyCheckBox"] = "No".
How can i do to make it work?
Or is there any way to get bool values(true/false) instead of string values ?
Need help
Try this:
editoptions: { value:"True:False" }, editable:true, edittype:'checkbox',
formatter: "checkbox", formatoptions: {disabled : false}
It seems to me you describe the bug which is already fixed in the last version of jqGrid from GitHub. I recommend you to download the version from here. See here for the description of the order of the including of the jqGrid moduls.

Resources