The autoencode parameter of jqGrid is set to true, which may cause Encoding Problems on the client.

Source: Internet
Author: User
Tags html encode jqgrid

The autoencode parameter of jqGrid is set to true, which may cause Encoding Problems on the client.

Not long ago, I used jqGrid + MVC for some time.

In the beginning, the paging parameters are almost all default values, and the paging function of jqGrid is very useful.

Considering that the each input is edevil, our system has high security requirements. Therefore, in order to ensure that the input and output are reliable, I found the information on the Internet, it is found that the autoencode parameter can meet the requirements.

By the way, I have referred to many Chinese reference articles on jqGrid. Most of them only refer to url encoding, which is not clear, it will also cause a lot of interference to my troubleshooting.

 

In addition to paging, we also need to add operation columns to the last column of the List to perform common operations such as update and delete. Then we found the problem: Garbled characters were found in the Operation column.

For example, if there is a paging list and the last operation column is added with the "edit" and "delete" links, follow the common jqGrid practices, we use the simple concatenation string in the gridComplete callback function to edit and delete the result. The sample code is roughly as follows:

GridComplete: function () {var ids = jQuery ("# yourGridtable "). jqGrid ('getdataids '); for (var I = 0; I <ids. length; I ++) {var itemID = ids [I]; var strUpdate = "<a href = 'javascript :; 'class = 'update' name = 'btnedit 'id = 'btnedit _ "+ itemID +"'> modify </a> & nbsp; | & nbsp ;"; var strDel = "<a href = 'javascript :; 'class = 'del 'name = 'btndelete' id = 'btndelete _ "+ itemID +" '> Delete </a> "; $ (" # yourGridtable "). jqGrid ('setrowdata', ids [I], {UserAction: strUpdate + strDel});} setTimeout (function () {// todo setting and editing effect // todo setting and deleting effect}, 200 );}GridComplete

However, the spliced string is html encoded on the page, and there are no "modify" or "delete" links.

The first response to this problem is that the string is not spliced correctly. This is not the reason after the check.

Then, I found that the autoencode parameter was set to true only after I checked n parameters for a bunch of materials and followed up the source code of jqGrid.

Refer to the official wiki and find that the autoencode parameter is described as follows:

When set to true encodes (html encode) the incoming (from server) and posted data (from editing modules). For example <will be converted to & lt ;.

When this parameter is set to true, both the client request and the data returned by the server are encoded in html, for example, <encoded as <;

The principle of html encoding is also very simple, that is, the escape of several special characters. paste the html encoding implementation source code of jqGrid:

   htmlEncode : function (value){        return !value ? value : String(value).replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");    }

So I suspect that the cause of garbled characters is that when the gridComplete callback function is triggered, the internal logic indirectly calls the html encoding function htmlEncode of jqGrid (the dynamic addition of row data addRowData function may call the html encoding logic ).

Set autoencode to false.

I was too lazy to code the text on the front-end, but it took a long time to think it was not worth it. I had to comfort myself and paste it to improve my experience.

 

Refer:

Http://www.trirand.com/jqgridwiki/doku.php? Id = wiki: options

Http://www.trirand.com/jqgridwiki/doku.php? Id = wiki: change # jqgrid_3.5.2_changes_and_fixes


Question about jquery's jqGrid field sorting

The key to sorting is the following two attributes: sortname: 'Eight ', // sorting by eight column during table loading by default
Sortorder: 'asc ', // default sorting method, same as asc and desc of the database
With sortable: true, the sorting is not added to colModel.




Default addition, deletion, modification, and query problems in the jqgrid navigation bar

Call jqGrid and use methods for common addition, deletion, modification, and query. The following code is a reference.

Jquery grid is a rich client-side jQuery Library Based on XML and Ajax grid plug-ins. JqGridView provides professional solutions to represent and edit table data on the network. Well-designed with powerful script APIs, this editable grid is a simple DHTML and XML configuration and shows compelling results and a large amount of data. Now I am familiar with jquery grid's usage and some common option settings.

Jquery grid is a rich client-side jQuery Library Based on XML and Ajax grid plug-ins. JqGridView provides professional solutions to represent and edit table data on the network. Well-designed with powerful script APIs, this editable grid is a simple DHTML and XML configuration and shows compelling results and a large amount of data. Now I am familiar with jquery grid's usage and some common option settings.
1. Call grid
JqGrid can obtain data from the Server and display the data in the Grid table. The following describes how to operate a Grid table and its data.
JqGrid has many method functions to operate data or operate the Grid table itself. JqGrid has two calling methods:

1 $ ("# grid_id"). jqGridMethod (parameter1,..., parameterN );
Or

1 $ ("# grid_id"). jqGrid ('method', parameter1,..., parameterN );
2. Common method functions (www.trirand.com/...ethods)
1. getGridParam
This method is used to obtain the option value of jqGrid. It has an optional parameter name, which represents the option name of jqGrid, for example:

1var id = $ ("# gridTable"). jqGrid ("getGridParam", "selrow ");
To obtain the ID of the currently selected row.
Note: selrow is one of the jqGrid options. The default value is null. This is a read-only option, representing the ID of the last selected row. If you perform paging or sorting, this option is set to null. Other options will be introduced later.
If the name parameter is not input, the entire jqGrid option options is returned.
2. getRowData
This method is used to obtain the data of a row. It has a rowid parameter. jqGrid returns the data of the corresponding row based on this rowid, and returns an array of the name: value type. For example:

1var getContact = function (){
2 var selectedId = $ ("# gridTable"). jqGrid ("getGridParam", "selrow ");
3
4 var rowData = $ ("# gridTable"). jqGrid ("getRowData", selectedId );
5
6 alert ("First Nam ...... remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.