当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - datatables-checkboxes plugin: how to use button to post the checked ids to the server side?

问题描述:

I use jquery datatables to show datatable datas and jQuery DataTables Checkboxes plugin to choose multiple row datas to post to the server side.

My datatable's data source is from DOM, the checkbox data is actually the row id in the database. Now I want to add several buttons upon/below the datatable, but I don't know how to realize. When I select the checkboxes which I want to post the id data to the server side, and click button A, this action will trigger server side ajax operations.(or click button B to trigger another ajax operations).

I have seen gyrocode's example, but in my case, different buttons correspond to different urls to perform different ajax operations. I'm a front-end rookie, I will appreciate your comments.

This is the html(use Jinja2 template) and js part of datatable:

$(document).ready(function() {

$('#dataTables-hosts').DataTable({

'scrollY': "600px",

'scrollCollapse': "true",

'columnDefs': [{

'targets': 0,

'checkboxes': {

'selectRow': true

}

}],

'select': {

'style': 'multi'

},

'order': [

[1, 'asc']

]

});

});

<div class="panel-body">

<div class="row">

<div class="col-sm-12">

<table width="100%" class="display" id="dataTables-hosts">

<thead>

<tr>

<th></th>

<th>IP Address</th>

<th>Status</th>

</tr>

</thead>

<tbody>

<!-- for -->

{% for host in hosts %}

<tr class="gradeA odd" role="row">

<td>{{ host.id }}</td>

<td>{{ host.IP }}</td>

<td>{{ host.status }}</td>

</tr>

{% endfor %}

</tbody>

</table>

</div>

</div>

</div>

分享给朋友:
您可能感兴趣的文章:
随机阅读: