Home  >  Article  >  Web Front-end  >  Detailed explanation of Easyui Datagrid custom button column

Detailed explanation of Easyui Datagrid custom button column

小云云
小云云Original
2018-01-01 10:36:302570browse

When working on a project, due to requirements, we need to add an operation column at the end of the table. EasyUI does not seem to provide this function. Let's customize the button column and implement the code. Please refer to this article. I hope it can help you. .

Version: jQuery easyUI 1.3.2

My implementation method here is in HTML form, the js method has not been used yet

The first is the HTML part


学号 姓名 性别 名族 家庭地址 手机号 出生日期 入学时间 操作
操作

Pay attention to the red part, which is our operation column. You can choose the name of the field casually. Here I am _operate. The key is the formatOper function


function formatOper(val,row,index){ 
  return '修改'; 
}

There are three parameters in the formatOper() function. val refers to the value of the current cell, row, the current row object, and index the index of the current row. Here we need this index

I pass this index Entering a function called editUser, why do we need to pass this index? Let’s take a look at this editUser function


function editUser(index){ 
  $('#dg').datagrid('selectRow',index);// 关键在这里 
  var row = $('#dg').datagrid('getSelected'); 
  if (row){ 
    $('#dlg').dialog('open').dialog('setTitle','修改学生信息'); 
    $('#fm').form('load',row); 
    url = '${ctx}updateStudent.do?id='+row.id; 
  } 
}

Looking through the easyUI documentation, we can find that datagrid has a method called selectRow


selectRow index Select a row, the row index start with 0.

Its function is to manually select the rows of the table. The parameter is the index value, starting from 0

In this way, we can get the mouse in real time Click on the data corresponding to the row


$('#dg').datagrid('selectRow',index);
var row = $('#dg').datagrid('getSelected');

These two sentences are to get the selected row

The specific effect is as shown in the figure

Related recommendations:

Example detailed explanation of adding operation buttons for each row of data in EasyUI's DataGrid

Detailed explanation of Datagrid in EasyUi control

Detailed explanation of EasyUI's DataGrid binding Json data source method

The above is the detailed content of Detailed explanation of Easyui Datagrid custom button column. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn