I use client side library jqGrid. When I display column I use format options of column like this
{ name: 'Salary', index: 'Salary', width: 100, align: 'right', sortable: false,
editable: true, formatter: 'number',
formatoptions: { decimalSeparator: ",", thousandsSeparator: ".", decimalPlaces: 2} }
So, I format number to use “,” for decimal separator and “.” for thousands separator. But when I edit row this column has numbers formatted like “.” for decimal separator and “,”for thousands separator. How can I correct this behavior? I would like to have same formats (as in my code) in display and edit mode.
Thank you for any help!
Related
{
name: 'SelectedMaterial', datafield: 'SelectedMaterial',
sortable: false, align: 'center', width: '250', search: true,
formatter: 'checkbox', formatoptions: { disabled: false },
edittype: "checkbox", editoptions: { value: "Yes:No"}
}
based on value return from database, set checkbox checked or unchecked
You use formatter: 'checkbox' which parse the input data and display unchecked checkbox if the data is one of the following values: false, f, 0, no, n, off. All other input values will be displayed as the checked checkbox. I would recommend you to use 0 and 1 (corresponds to bit datatype of Transact-SQL) or true and false (corresponds to Boolean datatype, which exist in the most computer languges) as the input values.
I was create kendo grid with sortable: true property and turn off sorting for some columns by setting property sortable to false
this._grid = $('#findResultsGrid').kendoGrid ({
sortable: true,
groupable: {
messages: {
empty: 'drag columns here'
}
},
scrollable: true,
columns:[
{
width: '100px',
title: 'Project',
field: 'PROJECT',
template: '<p style="' + defaultStyle + '">#=PROJECT#</p>'
},
{
width: '100px',
title: 'Well',
field: 'SLHOLENAME',
sortable: false,
template: '<p style="' + defaultStyle + '">#=SLHOLENAME#</p>'
},
...
But some columns without sort disabling (has no option sortable: false) not sortings and looks as not sortable
Sorry, i found my own bug while prepared reproducing example - unsortable columns has not filled field property
Same problem. The field property of a column needs to be set for column sorting to work. Since:
columns.sortable: If set to true the user can click the column header and sort the grid by the column field when sorting is enabled.
Another case of this problem is when you have numerical fields if one of them is 0, it will be considered as not set.
To fix this, prefix an empty string to it to force its conversion to string:
field: '' + item.field,
I hava a problem in the filter functionality for a column thats has dropdown values .Below is my code,
{
name: 'statusFlag',
width: 130,
editable:true,
edittype:'select',
formatter : 'select',
searchoptions:{sopt:['cn','eq','ne']},
editoptions:{value:{Y:'Active',N:'Inactive'}}
}
If I perform search with 'y' I am seeing records with column value active, and If I perform search with 'n', I am seeing records with column value inactive. I want the same functionality to work when I enter active and inactive instead of y /n. How should i changed the code. Should i use formatOptions or anything else.
You need add stype: "select" property and extend searchoptions with value:
{
name: 'statusFlag',
width: 130,
editable: true,
edittype: 'select',
formatter: 'select',
searchoptions: { sopt: ['eq', 'ne'], value: ':Any;Y:Active;N:Inactive' } },
editoptions: { value: 'Y:Active;N:Inactive' }
}
The usage of :Any part in searchoptions.value is recommended if you use filterToolbar. If you use only searching dialog then you can remove the value and just use the same value like in editoptions.
My format options are being ignored:
{name:'effectiveDate',
width:'80',
align: 'center',
editable:true,
formatter: 'date',
srcformat:'ISO8601Short',
newformat: 'Y-m-d',
edittype:'date',
editrules:{
required:true
}
}
The backend sends json dates in mm-dd-yyyy format. They are correctly parsed by jqGrid, the values are correct and displayed in the grid with m/d/y format, but I cannot change the formatting, no matter what I input for 'newformat', even if I input garbage it will just ignore it and always display m/d/y. Could it be that I'm missing the Formatter module, or is there another explanation? How can I verify if I have the Formatter module?
The properties srcformat and newformat are the options of formatter. So you should follow the documentation and rewrite the column definition to
{
name:'effectiveDate',
width: 80,
align: 'center',
editable: true,
formatter: 'date',
formatoptions: {
srcformat:'ISO8601Short',
newformat: 'Y-m-d',
},
editrules: {
required:true
}
}
By the way jqGrid don't know edittype: 'date'. See the documentation. The format mm-dd-yyyy is not ISO8601 date format. Correct ISO8601 format is yyyy-mm-dd. I hope the sever use the format in the JSON response.
I would like to use jqGrid for a great many grids that have only a small set of application-specific column types, and I would like to create a way to enforce consistency. For example, I want all my columns that show the compliance status of a row to have a certain format, be aligned a certain way, have specific search options, etc. So instead of having a colmodel entry like this:
{ name: 'ABC', width: 80, align: 'center', stype: "select",
searchoptions: { value: "1:Compliant;0:Not Compliant"} }
I would like to have one like this:
{ name: 'ABC', width: 80, mytype: compliancestatus }
where compliancestatus is a function I would write.
Is this kind of thing possible - without modifying the jqGrid source code? If so, can someone point me to an example of this type of extension?
Since jqGrid 3.8.2 are column templates supported.
You can just define for example
var compliancestatus = {
width: 80,
align: 'center',
stype: "select",
searchoptions: { value: "1:Compliant;0:Not Compliant" }
};
somewhere in the scope of visibility and then just use in colModel
{ name: 'ABC', template: compliancestatus }
In the template you can include any parameters. If the column definition has the same property but with the same value like
{ name: 'ABC', width: 100, template: compliancestatus }
the value from the colModel (width: 100 in the case) will be used.
I suggested the feature some time before and I use it intensively myself. For example I have many grids having many columns with checkboxes. I use the following template in the case:
mySettings.templateCheckbox = {
formatter: 'checkbox', align: 'center', width: 20,
edittype: 'checkbox', editoptions: { value: "1:0" },
stype: "select", searchoptions: { sopt: ['eq', 'ne'], value: ":Any;1:Yes;0:No" }
};
In the same way I defined many other templates which reduce the code of grids and improve managing of the common grid style.
If you want to change some common default settings for all columns you can use cmTemplate parameter of jqGrid. For example
cmTemplate: { align: 'center' }
You can use it as additional parameter of jqGrid or set it like any other default parameter with respect of
$.extend($.jgrid.defaults, {
cmTemplate: { align: 'center' }
});
Read more about the column templates here.