如何获取所选行的第一列值并使用jquery datatable删除所选行

时间:2014-02-11 12:34:35

标签: jquery jquery-plugins

iam newbie to jquery.Iam使用jquery datatable插件。我想获取所选行的第一列值,并在获取值后需要发出ajax请求。在ajax请求成功之后我需要删除该行。

我尝试了以下代码

var myjson='[{"isTruncated": "false","nextMarker": "null","marker": "null","prefix":   "Mymedia/mysys/","contents": [{"deviceInfo": "null","lastModified": "Thu Dec 26 16:36:42 IST 2013","etag": "d41d8cd98f00b204e9800998ecf8427e","key":"Mymedia/mysys/audio_$folder$","size": "0"},{"deviceInfo": null,"lastModified": "Thu Dec 26 16:36:11 IST 2013","etag": "d41d8cd98f00b204e9800998ecf8427e","key": "Mymedia/mysys/doc_$folder$","size": "0"},{ "deviceInfo": null,"lastModified": "Thu Dec 26 16:36:20 IST 2013", "etag": "d41d8cd98f00b204e9800998ecf8427e","key": "Mymedia/mysys/imge_$folder$","size": "0"},{"deviceInfo": null,"lastModified": "Thu Dec 26 16:36:56 IST 2013","etag": "d41d8cd98f00b204e9800998ecf8427e","key":"Mymedia/mysys/others_$folder$","size": "0"},{"deviceInfo": null,"lastModified": "Thu Dec 26 16:36:32 IST 2013","etag": "d41d8cd98f00b204e9800998ecf8427e","key": "Mymedia/mysys/video_$folder$","size": "0"}],"name": "name", "statusCode": "200","statusMessage": "Success","error": null}]';

Mytable here

如果我点击表格中的deletesymbol,我需要获取第一列值,我需要删除该行。

任何人都可以帮助我解决这个问题。

这是否可能与DATATABLE或不是???

1 个答案:

答案 0 :(得分:0)

以下代码可用于获取在datatable插件中选择的行的第一列值。在这里你可以看到delete_params和request_call这是一个从数据库中删除值的ajax调用,所以你可以避免这些代码。

 oTable = $('#example').dataTable({
                         "bDestroy": true,
                         "bPaginate": false,
                         "aaData": Listobj,
                         "bLengthChange": false,
                         "iDisplayLength": 10,
                         "sDom": 'T<"clear">lfrtip',
                         "oTableTools": {
                             "sRowSelect": "single"
                         }
                     });

                     $('#example tr').click(function () {
                         $(this).toggleClass('row_selected');
                     });

                     $('#example tbody tr').live('click', function (event) {
                         var aData = oTable.fnGetData(this);
                         if (null != aData) {
                             var colun_data = aData[0];
                       /*****  var delete_params = { "objectName": colun_data
                             };
                             Request_Call(delete_params, Tablevalues_callback, delete_URL);******/
                         }
                         var anSelected = fnGetSelected(oTable);
                         if (anSelected.length !== 0) {
                             oTable.fnDeleteRow(anSelected[0]);
                         }
                     });

   function fnGetSelected(oTableLocal) {
        return oTableLocal.$('tr.row_selected');
 }