最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Easyui Datagrid自定義按鈕列(最后面的操作列)

 更新時(shí)間:2017年07月13日 11:52:28   作者:青青姜的編程日記  
做項(xiàng)目的時(shí)候因?yàn)樾枨?要在表格的最后添加一列操作列,easyUI貌似沒有提供這種功能,下面我們來自定義按鈕列,具體實(shí)現(xiàn)代碼,大家參考下本文吧

做項(xiàng)目的時(shí)候因?yàn)樾枨?要在表格的最后添加一列操作列,easyUI貌似沒有提供這種功能,不過沒關(guān)系,我們可以自定義來實(shí)現(xiàn)

版本:jQuery easyUI 1.3.2

這里我的實(shí)現(xiàn)方式是采用HTML形式,js方式暫時(shí)還沒用到

首先是HTML部分

<table id="dg" title="學(xué)生信息" class="easyui-datagrid" 
      url="${ctx}listStudent.do" 
      toolbar="#toolbar" pagination="true" 
      rownumbers="false" fitColumns="true" singleSelect="true"> 
    <thead> 
      <tr> 
        <th data-options="field:'stuNo',sortable:true,width:20">學(xué)號</th> 
        <th data-options="field:'name',width:20">姓名</th> 
        <th data-options="field:'gender',width:20,formatter:formatGender">性別</th> 
        <th data-options="field:'nationality',width:20">名族</th> 
        <th data-options="field:'address',width:50,formatter:formatAddr">家庭地址</th> 
        <th data-options="field:'mobile',width:20">手機(jī)號</th> 
        <th data-options="field:'birthday',width:20">出生日期</th> 
        <th data-options="field:'registDate',sortable:true,width:20">入學(xué)時(shí)間</th> 
        <th data-options="field:'_operate',width:80,align:'center',formatter:formatOper">操作</th> 
      </tr> 
    </thead> 
  </table> 
<th data-options="field:'_operate',width:80,align:'center',formatter:formatOper">操作</th>

注意紅色部分,就是我們的操作列,field的名字隨便取,我這里是_operate,關(guān)鍵是formatOper函數(shù)

function formatOper(val,row,index){ 
  return '<a href="#" rel="external nofollow" onclick="editUser('+index+')">修改</a>'; 
} 

formatOper()函數(shù)中有三個(gè)參數(shù),val指當(dāng)前單元格的值,row,當(dāng)前行對象,index當(dāng)前行的索引.這里我們就需要這個(gè)index

我把這個(gè)index傳入了一個(gè)叫editUser的函數(shù)中,為什么要傳這個(gè)index呢,我們在來看下這個(gè)editUser函數(shù)

function editUser(index){ 
  $('#dg').datagrid('selectRow',index);// 關(guān)鍵在這里 
  var row = $('#dg').datagrid('getSelected'); 
  if (row){ 
    $('#dlg').dialog('open').dialog('setTitle','修改學(xué)生信息'); 
    $('#fm').form('load',row); 
    url = '${ctx}updateStudent.do?id='+row.id; 
  } 
} 

翻閱easyUI文檔可以發(fā)現(xiàn)datagrid有一個(gè)方法叫selectRow

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

它的作用就是手動(dòng)選中表格的行,參數(shù)就是index值,從0開始

這樣,我們就能實(shí)時(shí)獲取到鼠標(biāo)點(diǎn)擊行所對應(yīng)的數(shù)據(jù)了 

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

這兩句話就是獲取選中的行

具體效果如圖 

以上所述是小編給大家介紹的Easyui Datagrid自定義按鈕列(最后面的操作列),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

桐城市| 育儿| 唐海县| 深泽县| 太康县| 崇文区| 苗栗县| 昭平县| 新巴尔虎右旗| 舞阳县| 河南省| 建宁县| 大化| 南乐县| 崇义县| 巩留县| 安达市| 盈江县| 京山县| 南开区| 平昌县| 灵丘县| 宜兴市| 慈溪市| 遂川县| 民县| 东源县| 都兰县| 康马县| 北川| 甘孜县| 县级市| 景谷| 安福县| 陵水| 濮阳县| 台州市| 皋兰县| 仁布县| 永年县| 呼伦贝尔市|