Easyui DataGrid custom Button column, which is the Action column for the last Face

Source: Internet
Author: User

When doing the project because of the requirements, to add a column of action columns at the end of the table, Easyui doesn't seem to provide this functionality, but it doesn't matter, we can customize to implement

Version: jquery Easyui 1.3.2

Here my implementation is in the form of HTML, JS mode is temporarily useless to

The first is the HTML section

<table id= "DG" title= "Student Information" class= "Easyui-datagrid" url= "${ctx}liststudent.do" toolbar= "#toolbar" pagination= "Tru E "rownumbers=" false "fitcolumns=" true "singleselect=" true "> <thead> <tr> <th data-options=" Field: ' Stuno ', sortable:true,width:20 ' > </th> <th data-options= ' field: ' Name ', width:20 ' > Name </th > <th data-options= "field: ' Gender ', width:20,formatter:formatgender" > Sex </th> <th data-options= "fi Eld: ' Nationality ', width:20 > Clan </th> <th data-options= ' field: ' Address ', width:50,formatter:formataddr ' > Home Address </th> <th data-options= "field: ' Mobile ', width:20" > Phone number </th> <th data-options= "field: ' Bi Rthday ', width:20 "> Date of birth </th> <th data-options=" field: ' Registdate ', sortable:true,width:20 "> Admission Time < /th> <th data-options= "field: ' _operate ', width:80,align: ' Center ', formatter:formatoper ' > Operations </th> < /tr> </thead> </table>

<th data-options= "field: ' _operate ', width:80,align: ' Center ', formatter:formatoper ' > Operations </th>
Note that the red part, is our Operation column, field name casually take, I here is _operate, the key is Formatoper function

function Formatoper (val,row,index) {
	return ' <a href= ' # ' onclick= ' Edituser (' +index+ ') ' > Modify </a> ';
}


There are three parameters in the Formatoper () function, Val refers to the current cell value, row, current Row object, index of the current row of index. We need this index here.

I put this index into a function called Edituser, why to pass this index, we are looking at this edituser function

function Edituser (index) {
	$ (' #dg '). DataGrid (' SelectRow ', index);//Key here
	var row = $ (' #dg '). DataGrid (' GetSelected ');
	if (row) {
		$ (' #dlg '). Dialog (' Open '). dialog (' Settitle ', ' modify student information ');
		$ (' #fm '). Form (' Load ', row);
		url = ' ${ctx}updatestudent.do?id= ' +row.id;
	}
}

Flip through the Easyui document to find a way for the DataGrid to be called SelectRow

SelectRow Index Select a row, the row index start with 0.

Its function is to manually select the table row, the parameter is the index value, starting from 0

In this way, we can get the data corresponding to the mouse click line in real time.

$ (' #dg '). DataGrid (' SelectRow ', index);

var row = $ (' #dg '). DataGrid (' getselected ');

These two words are to get the selected row

Concrete effect as shown in figure

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.