2014-04-01 37 views
0

我有一個帶數據的數據表,當我點擊上面的一個數據時,我希望能夠獲得該值並執行一些操作。如何從jquery數據表中獲取單元值

我試過用「fnGetData」函數,但它不起作用。

我有這樣的代碼:

cclients.otable=$('#turlexceptions').dataTable({ 
     'bDestroy': true, 
     'bAutoWidth': false, 
     'sDom': "<'row'<'span5'><'dtrt'>r>t<'row'<'span5'><'dtrt'>>", 
     'sScrollY': '200px', 
     'bPaginate': false, 
     'bScrollCollapse': true, 
     "aaData": cclients.urlexceptions($('#icle_s_urlexcept').val()), 
     'aoColumnDefs': [ 
      {'aTargets':[0],'sTitle':'Webs No Registradas'}, 
      {'aTargets':[1],'sName':'remove','sTitle':'','sWidth':'15px','mDataProp':null,'bSearchable':false,'bSortable':false,'sClass':'tdactions','sDefaultContent':'<a href="javascript:cclients.removeurlexception('+ $(this).text()+')" class="eremove label label-important" title="Remove">x</a>'} 
     ] 
    }); 

感謝。

+0

該值?你的意思是TD文字嗎? –

+0

我做了幾次測試後寫了$(this).text()。 我需要從所選單元格中獲取colunm [0]中的值 – edraven

回答

0

首先初始化數據表如下:

var userTable =$('#turlexceptions').dataTable({ 
     'bDestroy': true, 
     'bAutoWidth': false, 
     'sDom': "<'row'<'span5'><'dtrt'>r>t<'row'<'span5'><'dtrt'>>", 
     'sScrollY': '200px', 
     'bPaginate': false, 
     'bScrollCollapse': true, 
     "aaData": cclients.urlexceptions($('#icle_s_urlexcept').val()), 
     'aoColumnDefs': [ 
      {'aTargets':[0],'sTitle':'Webs No Registradas'}, 
      {'aTargets':[1],'sName':'remove','sTitle':'','sWidth':'15px','mDataProp':null,'bSearchable':false,'bSortable':false,'sClass':'tdactions','sDefaultContent':'<a href="javascript:cclients.removeurlexception('+ $(this).text()+')" class="eremove label label-important" title="Remove">x</a>'} 
     ] 
    }); 



-------------------- 

For get the selected data: 

var position = userTable .fnGetPosition(this); 
if(position !=null){ 

    var selectedData = userTable .fnGetData(position); 
    alert("SELECTED DATA::"+selectedData); 

} 
+0

它不起作用 當我嘗試讀取var position = userTable .fnGetPosition(this); 我收到錯誤 – edraven

+0

你在哪裏添加了這段代碼。當你點擊任何元素時需要選擇的數據? – TELMILA

+0

我只添加了:var userTable ...對於數據表代碼和第二部分代碼(var position .....)在一個函數中(javascript:cclients.removeurlexception)=>這是我在colunm中的href刪除 – edraven