Javascriptjqueryjqgridformatter
The format setting for the List cell property in Jqgrid is mainly set up by Colmodel formatter, formatoptions, and basic usage:
JQuery ("#jqGrid_id"). Jqgrid ({... Colmodel: [... {name: ' Price ', index: ' Price ', formatter:' integer ', formatoptions:{thousandsseparator: ', '}}, ... ] ...});
Formatter is mainly to set the format type (integer, email, and function to support the custom type), formatoptions to set the corresponding formatter parameters, Jqgrid predefined the common format and its options:
integerThousandsSeparator://thousand-separator,? 0?2defaulvalue
NumberDecimalSeparator,//decimal separator, such as "." ThousandsSeparator,//thousand separator, such as "," decimalPlaces,//decimal reserved number of digits Defaulvalue
CurrencyDecimalSeparator,//decimal separator, such as "." ThousandsSeparator,//thousand separator, such as "," decimalPlaces,///decimal reserved digits defaulvalue,prefix//prefix, such as add "$" suffix//suffix
DateSrcformat,//source original format Newformat//new format
EmailNo parameters, will be in the cell is email plus: mailto:[email protected]
ShowlinkBaselinkurl,//Add the URL of link in the current cell, such as "Jq/query.action" showaction,//Add &action=actionnameaddparam after Baselinkurl, Add additional parameters after Baselinkurl, such as "&name=aaaa" Target,idname? 0?2? 0?2//default will be added after Baselinkurl, such as ". Action?id=1". If you set idname= "name", then ". Action?name=1". Where the value is the current ROWID
checkboxDisabled 0?2? 0?2//true/false Default to True the checkbox cannot be edited at this time, as the current cell's value is 1, 0 will select 1
SelectSet drop-down box, no parameters, need and Colmodel in the editoptions with the following is an example of use:
var datas = [ {"id": 1, "name": "Name1", "price": 123.1, "email": "[email protected]", "Amount": 1123423, " Gender ":" 1 "," type ":" 0 "}, {" id ": 2, " name ":" Name2 ", " price ": 1452.2, " email ":" [email protected] "," Amount ": 12212321," Gender ":" 1 "," type ":" 1 "}, {" id ": 3, " name ":" Name3 ", " price ": 125454," email ": [Email Protected] "," Amount ": 2345234," gender ":" 0 "," type ":" 0 "}, {" id ": 4, " name ":" Name4 ", " price ": 23232.4 , "email": "[email protected]", " Amount": 2345234, "Gender": "1", "type": "2"}]
? 0?2
colmodel:[ Formatter:customfmatter}, {name: ' name ', index: ' name ',formatter: ' Showlink ', Formatoptions:{baselinkurl: "Save.action", Idname: "id", AddParam: "&name=123"}}, formatter: " Currency", formatoptions: {thousandsseparator:", ", DecimalSeparator:". ", Prefix:" $ "}}, formatter: "Email"}, formatter: "number", Formatoptions: {thousandsseparator: ",", Defaulvalue: "", Decimalplaces:3}}, {name: ' Gender ', Index: ' Gender ',Formatter: ' checkbox ', formatoptions:{disabled: False}, formatter: "select", Editoptions:{value: "0: Invalid; 1: normal; 2: Unknown"}} ],
Where Customfmatter declares the following
function Customfmatter (cellvalue, Options, Rowobject) {console.log (cellvalue); Console.log (options); Console.log ( Rowobject); return "[" +cellvalue+ "]";};
The effect of 0?2 on the page is as follows: Of course, you have to support the custom formatter function, just
Formatter:Customfmatter set the Formatter function, which has three signatures
function Customfmatter (cellvalue, Options, Rowobject) {}//cellvalue-the value of the current cell//options-the cell's options settings, including {rowId, Colmodel,pos,gid}//rowobject-The value of the current cell's row, such as {id=1, name= "name1", price=123.1, ...}
0?2 of course, for custom formatter, you need to get the original value in the modification, here is the Unformat function, see the example of the official website:
JQuery ("#grid_id"). Jqgrid ({... Colmodel: [... Formatter:imageformat, Unformat:imageunformat}, ... ] ...}); function ImageFormat (cellvalue, Options, Rowobject) {return ' ';} function Imageunformat (cellvalue, options, cell) {return $ (' img ', cell). attr (' src ');}
0?2 attached official website doc:http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatterhttp://www.trirand.com/ Jqgridwiki/doku.php?id=wiki:predefined_formatter
[Transfer from]http://mj4d.iteye.com/blog/1634857
The formatter in Jqgrid