jqGrid principle
JqGrid is a typical B/S architecture. The server only provides data management, while the client only provides data display. In other words, jqGrid can present information about your database in a simpler way, and it can also send client data back to the server.
For jqGrid, what we care about is that there must be a piece of code to save some page information to the database, and also to be able to return the response information to the client. JqGrid uses ajax to handle requests and responses.
jqGrid | Initialization | Parameters
Name | describe |
url | Address to get data |
datatype | The data type returned from the server side defaults to xml. Optional types are: xml, local, json, etc. |
mtype | ajax submission, POST or GET. Default GET. |
colNames | Column display name, is an array of objects. |
colModel | Commonly used attributes: name: column display name; index: column name passed to the server for sorting; width: column width; align; sortable: sortable can be sorted; |
pager | Defining the navigation bar for page turning must be a valid html element. Page turning tools can be placed anywhere on the page. |
rowNum | The number of records is displayed on the grid, and this parameter is passed to the background. |
rowList | A drop-down selection box is used to change the number of display records. When selected, the rowNum parameter is overwritten and passed to the background. |
viewrecords | Define whether to display the total number of records |
caption | Table name |
direction | The display direction of the text in the table, from left to right (ltr) or from right to left (rtl) |
editurl | Define the url when editing form |
height | Table height, which can be a number, a pixel value, or a percentage |
prmNames | Default value sprmNames: {page:"page", rows:"rows", "sort:" sidx", order:" sord","search:"_search", "nd:" nd", npage:null} will not be sent to the server when the parameter is null. |
jqGrid colModel parameter
ColModel is one of the most important attributes in jqGrid, setting the attributes of table columns.
attribute | describe |
align | Alignment. Optional: left, center, right; |
classes | Set the css of the column. Multiple classes are separated by spaces, such as `class1 class2'. The default css attribute of the table is ui-ellipsis. |
datefmt | "/", -"..." are valid date separators. Date format, string Y-m-d |
editable | Is the cell editable |
editoptions | A series of options for editing. {name:'goodsId', index:'goodsId', width: 200, editable: true, edittype:'select', editoptions: {dataUrl: "goods_goodsEdit.do"}. Examples of dynamically retrieving data from the server side. |
editrules | Editorial rules {name:'age', index:'age', width: 90, editable: true, editrules: {edithidden: true, required: true, number: true, minValue: 10, maxValue: 100} sets the maximum age to be 100, the minimum value to be 10, and the number type, and the required field. Special note: If a field has letters or symbols, it will fail here. |
fixed | Do column widths need to be fixed and immutable |
formoptions | Property settings for form editing |
formatoptions | Formatting some columns |
formatter | The name or type of function that is set when a column is formatted. {name:'sex', index:'sex', align:'center', width: 60, editable: true, edittype:'select', editoptions: {value:'0: to be determined; 1: male; 2: female'}, formatter: function(cellvalue, options, rowObject){ var temp = "<img src = './img/" if (cellvalue == 1) { temp = temp + "male.png"; } else if (cellvalue == 2) { temp = temp + "female.png"; } else { temp = temp + "user.png"; } temp = temp + " 'border = ' 0'/> " return temp; }} The // return gender Icon |
hidden | Do you want to hide this column when initializing the table? |
index | Indexes. The parameter that it interacts with the background is sidx |
label | If colNames is empty, use this value as the display name of the column, and if none is set, use the name value. |
name | Names of table columns, all keywords and reserved words can not be used as names, including subgrid, cb, rn |
sortable | Is it sortable? |
sorttype | Used when the datatype is local, define the type of search column, optional value: int/integer, sort integer; float/number/currency, sort number; date: sort date; text: sort text. |
width | The width of the default column can only be a pixel value, not a percentage. |
unformat | 'unformat'cell value |
edittype | Editable type. Optional values: text, textarea, select, checkbox, password, button, image, file. |