本文介绍了数据表甚至在最后一列上单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似此代码的数据表

I have datatables like this code

var table = $("#mas-vendor");
    var filter = $('.form-filter');
    var target = table.attr('data-table');
    var oTable = table.on( 'processing.dt', function ( e, settings, processing ) {
            if (processing) {
                $(this).find('tbody').addClass('load1 csspinner');
            } else{
                $(this).find('tbody').removeClass('load1 csspinner');
            };
        } ).DataTable({
            "ajax": host+'datatable/'+target,
            "bServerSide": true,
            "iDisplayLength" : 10,
            "order": [[ 1, "desc" ]],
            "columnDefs": [{
                "targets": [ 0 ],
                "className": "details-control",
            },]
        });

和这样的html

<table id="mas-vendor" class="dataTable table table-bordered table-hover table-full-width" width="100%" data-table="masvendor">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Country</th>
                                <th>Terms</th>
                                <th>Cheque/Giro Name</th>
                                <th>PPN</th>
                                <th>NPWP</th>
                                <th>Status</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                    </table>

像这样在json上(仅作为示例)

on json like this (just example)

$json['data'][] = [$val['vendor'], $val['country'], $val['terms'], $val['cgname'], $val['ppn'], $val['NPWP'], $val['status'],'<a href="javascript:;" id="delete">Delete</a> || <a href="javascript:;" id="edit">Edit</a>'];

我的问题是我什至需要单击最后一列(动作),而不是所有列,并且我怎么知道ID是删除还是编辑.有人可以帮我吗?

And my problem is i need even click on last column (action) not all column, and how do i know if id is delete or edit. Can someone help me??

我想尝试使用此代码,

table.find('tbody').on('click', 'td a', function (){});

但是我仍然不知道如何在最后一列中使用它

but i'm still dont know how to use it on last column

更新:我的问题已清除!!! Tick Vicky_Thinking !!! ;)

UPDATE : MY PROBLEM CLEAR!!! tq for Vicky_Thinking!!! ;)

推荐答案

尝试一下

table.find('tbody').on('click', 'td:last-child a', function (){});

这将使最后一列的所有行都可单击.

It will make all rows of last column clickable.

这篇关于数据表甚至在最后一列上单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 11:04