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.
Related
I am using jqGrid to bind data and i have a date field which i am binding it to grid. The date is 01/01/0001, but when i try to bind it to grid, it is displaying as 1/1/1. How can i display with out truncating zeros.
I am using "Guriddo jqGrid JS - v5.2.1"
below is my sample colModel for the date i have implemented
{
name: "orderDate",
label: "orderDate",
align: "left",
jsonmap: "orderDate",
formatter: "date",
formatoptions: { newformat: 'm/d/Y' }
}
First of all you will need to set the source format (srcformat). The default srcformat is Y-m-d
In you case you will need to set:
{
name: "orderDate",
label: "orderDate",
align: "left",
jsonmap: "orderDate",
formatter: "date",
formatoptions: { srcformat : m/d/Y, newformat: 'm/d/Y' }
}
Second which is more important is that dates in Javascript begin since 1 jan 1970. Your source date is not correct and it will be not interpreted correcy
In your case you will need to define your own (custom) formatter to do what you want.
{
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 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.
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.
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!