- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个显示 mysql 寄存器的动态表 (id, product, quantity, price
),每个寄存器都有一个 checkbox
,另一个 checkbox
“选中/取消选中所有” 对列表中的产品求和并显示在名为 total 的 input:text
上。
动态表有一个分页器,因为它上传了很多数据库的寄存器,checkbox
完美地工作,并进行求和,但它只是在第 1 页进行,当我切换到第 2 页,这是取消标记,我必须单击“选中/取消选中所有”才能标记第 2 页表格的所有复选框,并求和总和实际页面和最后一页,依此类推。
我想标记“选中/取消选中所有”的复选框
,这可以选择所有页面的所有复选框
列表动态表;
抱歉我的英语不好,谢谢。
我同时处理的寻呼机调用 DataTables
,这是我正在使用的代码:
let buys = document.getElementById('tbl-buys');
let cboxAll = buys.querySelector('thead input[type="checkbox"]');
let cboxes = buys.querySelectorAll('tbody input[type="checkbox"]');
let totalOutput = document.getElementById('total');
let total = 0;
[].forEach.call(cboxes, function (cbox) {
cbox.addEventListener('change', handleRowSelect);
});
cboxAll.addEventListener('change', function () {
[].forEach.call(cboxes, function (cbox) {
//cbox.checked = cboxAll.checked;
cbox.click();
});
});
function handleRowSelect (e) {
let row = e.target.parentNode.parentNode;
let qty = row.querySelector('td:nth-child(3)').textContent;
let price = row.querySelector('td:nth-child(4)').textContent;
let cost = Number(qty) * Number(price);
if (e.target.checked) {
total += cost;
} else {
total -= cost;
}
total = Number(total.toFixed(2));
totalOutput.value = total;
}
$(document).ready(function(){
$('#tbl-buys').DataTable({
"columnDefs": [ { orderable: false, targets: [0] }],
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
<table class="table table-striped table-bordered" data-page-length='2' id="tbl-buys">
<thead>
<tr>
<th>
<input type="checkbox"/>
</th>
<th>Producto</th>
<th>Cantidad</th>
<th>Precio</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="checkbox"/>
</td>
<td>Laptop Dell XPS 15</td>
<td>1</td>
<td>782.49</td>
</tr>
<tr>
<td>
<input type="checkbox"/>
</td>
<td>Mouse bluetooth solar</td>
<td>1</td>
<td>19.90</td>
</tr>
<tr>
<td>
<input type="checkbox"/>
</td>
<td>Sony Headphones 1000px</td>
<td>1</td>
<td>29.90</td>
</tr>
<tr>
<td>
<input type="checkbox"/>
</td>
<td>Intel x99</td>
<td>1</td>
<td>200.00</td>
</tr>
</tbody>
</table>
<label>Total</label>
<input type="text" id="total" class="form-control" readonly value="0.0" />
最佳答案
使用复选框插件,我不再需要跟踪复选框。因为他的插件在选中时将一行标记为已选中,所以我也不必再将数据标记为已选中。
简单的求和函数获取选定的行并对它们进行总计。我把总数放在工资栏的底部。
此代码在我自己的环境中工作,但无法将其放入 jsbin,因为我使用 ajax 从我的盒子上的 Web 服务获取数据。
我还使用了一个不同的插件,称为 autoNumeric 来格式化总数。
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<link rel="stylesheet" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://gyrocode.github.io/jquery-datatables-checkboxes/1.0.4/css/dataTables.checkboxes.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="//gyrocode.github.io/jquery-datatables-checkboxes/1.0.4/js/dataTables.checkboxes.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/autonumeric/1.9.46/autoNumeric.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
// the checkbox plugin selects the row when
// clicked so all this function has to do it get the selected rows.
$.fn.dataTable.Api.register('sum()', function () {
var r = this.rows(".selected").data();
var total = 0;
$.each(r, function (i, it) {
total += it.salary;
});
// I put the number in the footer of the salary column
// using the autoNumeric plugin to format the amount.
$("#total").autoNumeric("set",total);
});
var table = $('#example').DataTable({
'processing': false,
// Again, this code will not work if serverSide is set to true.
'serverSide': false,
'ajax': {
// I used an asmx page in my own development environment to get the data.
url: 'wsService.asmx/GetDTDataSerializedList',
type: "post",
data: function(dtparms){
return JSON.stringify({ parameters: JSON.stringify(dtparms) });
},
contentType: "application/json; charset=utf-8",
dataFilter: function (dtData) {
var p = JSON.parse(dtData);
var d = JSON.parse(p.d);
return JSON.stringify({ data: d });
},
},
'columnDefs': [
{
'targets': 0,
'checkboxes': {
'selectRow': true
}
}
],
'select': {
'style': 'multi'
},
'columns': [
{ data: null },
{ data: "name" },
{ data: "position" },
{ data: "office" },
{ data: "extn" },
{ data: "start_date" },
{ data:"salary", className:".salary"}
],
'order': [[1, 'asc']],
initComplete: function () {
$("#total").autoNumeric("init", { "currencySymbol": "$" });
$("#total").autoNumeric("set", 0);
}
});
// event handler for individual rows
$("tbody" ).on("click","input[type=checkbox]", function () {
table.data().sum();
});
$("thead").on("click", "th input[type=checkbox]", function () {
table.data().sum();
});
});
</script>
</head>
<body>
<form>
<div>
<table class="display" id="example" cellspacing="0">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th id="total"></th>
</tr>
</tfoot>
</table>
</div>
</form>
</body>
</html>
关于javascript - 带有寻呼机 DataTable 的复选框 "check/uncheck all",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42565336/
我需要能够垂直翻转一组图像。我看过使用 ViewPager,但它似乎只支持水平分页。 我也查看了 Gallery,但我也没有看到垂直分页的方法。无论如何,它已被弃用,取而代之的是 Horizont
我正在使用寻呼机中内置的 View ,并且希望有一个“显示全部”选项。即显示全部 第 2 页,共 10 页。 实现这一目标的最佳方法是什么? 史蒂夫 最佳答案 史蒂文,您可以克隆您的实际显示,然后在
当我使用 vim 编辑 Markdown 文件时,我有很好的语法着色(通过 vim-markdown 和 vim-markdown-preview 插件)。 当我使用 less(寻呼机)查看文件时,我
在我的 Android 应用程序中,我已经能够在一段时间后自动滚动查看寻呼机。我找不到显示滚动发生前剩余时间的寻呼机指示器。 我在下面附上了一个网站的屏幕截图,以了解我想要实现的目标。 如果您可以共享
当您编写的每个代码都立即运行并且您未按时完成计划时,您是否知道这种感觉:-P 就像'哦,是的,现在我有时间让它变得完美'。这就是我现在的位置^^ 所以我用 JSF (ui:repeat) 实现了一个转
我在 Android 应用程序中有一个项目列表,我希望每个项目都在一个页面上。问题是每个项目都设置了一个带有 imageview 的布局,它从一个唯一的 url 下载它的图像。这有可能实现吗?如何实现
我想同步两个 View 寻呼机之间的触摸事件。我已经试过了,但没有发现任何效果。 viewPager.setOnTouchListener(new View.OnTouchListener() {
我必须构建具有无限自动滚动功能的 View 寻呼机。我还需要在 View 寻呼机下方显示一个页面指示器,它应该根据滚动事件做出响应。目前我已经为无限自动滚动应用了以下逻辑: public void s
我正在尝试按照一些教程使用 View 寻呼机创建一个自动图像 slider 。我让一切正常,但后来我看到了 编舞:跳过 1 帧!应用程序可能在其主线程上做了太多工作。 并搜索了错误。` 你看,在我的代
如何从viewpager的第0个index跳转到view pager的最后一个index?那就是如何让view pager循环呢?如果用户向左滑动,我想跳转到最后一个索引;如果用户向右滑动,我想从最后
我在一个 iOS 应用程序上工作,它从服务器获取视频和图像,每个对象都有很多图像和视频,我需要在 slider (寻呼机)中显示这些图像和视频,用户可以在其中滑动以获取下一个,并且我需要将这些视频和图
我们目前正在使用 VS 2008 C# 开发 Windows 窗体应用程序。此应用程序用于阅读长(200 - 300 页)的法律文件,它处理大约 30 - 40 个文档。应用程序在文档文本中搜索,在文
我正在开发一个项目,其中我在一个屏幕上使用 View Pager,如下所示: 但是你可以在那里看到,有一个上层布局,其中列出了根据显示的页面选择的年份。当我们滑动 View 寻呼机时,年份也会根据显示
我需要在带有图像的 View 寻呼机文件中获取页面指示器。这是我的代码。 public class IndicatorActivity extends Activity { /** Called w
有没有办法用代表每张幻灯片的单词替换寻呼机中 slider 的圆圈(就像可单击的菜单,滑动其下方的内容)?选项在这里http://bxslider.com/options但不确定哪一个可以实现这一目标
ViewPager 叠加在 fab 之上。如何将 fab 放在首位? xml: 或者也许这不是原因?当我在上面时,只是没有按下按钮,但选项卡被翻转。 最佳答案 Coordinat
我正在尝试实现一个垂直可滑动的ViewPager,它有一堆卡片,就像外观一样。 我能够使用 ViewPager.PageTransformer 并交换触摸点来实现 VerticalViewPager。
我无法以编程方式创建和添加 View 寻呼机。 我找到了这个问题Android create ViewPager programmatically但接受的答案对我不起作用。 相关代码如下。
我有一个 View 寻呼机,其中每个页面都是一个自定义 View ( ... 而不是 Fragment ),我正在使用 LayoutInflator 进行扩充。 .每个自定义 View 都有一个 Im
我已经使用 jQuery 设置了一个动画 slider : jsFiddle 演示:http://jsfiddle.net/neal_fletcher/9zRDV/ 原因是我想在幻灯片上实现轻微的悬垂
我是一名优秀的程序员,十分优秀!