在DataTables中与条件进行计数器
您好,我有一个疑问,因为我使用DataTables,我有一个疑问,目前我有数据向我显示列中的采购订单,如果它没有一个,那么我使用Laravel和Blade Template有条件地向我展示破折号“ - ”或减法标志,现在我希望能够使我只计算具有订单的数据。
var contador = table.rows().count();
$("#counta").text((+contador));
我留下了我的采购订单部分的图像。
我如何调整该功能,以便如果它具有破折号或减法标志,则不会算出计数。
这是我的数据量代码,
$(document).ready(function(){
var table = $('#servicios').DataTable({
processing: true,
serverSider: true,
ordering: true,
"pageLength": 50,
"lengthMenu": [[5,10,50,-1], [5,10,50,"All"]],
"order": [[ 1, "asc" ]],
"autoWidth": false,
"language":{
"url": "//cdn.datatables.net/plug-ins/1.10.21/i18n/Spanish.json"
}
});
var contador = table.rows().count();
$("#counta").text((+contador));
//Counter of the column of purchase orders
var contador_oc = table.column(24).rows().count();
$("#counta_oc").text((+contador));
});
如果您帮助我解决它,我将非常感谢。
Hello I have a question about how to make a counter since I am using datatables, currently I have data that show me the purchase order in a column and if it does not have one then I make a conditional with laravel and blade template to show me a dash "-" or subtraction sign, now I want to be able to make me only count the data that have an order.
var contador = table.rows().count();
$("#counta").text((+contador));
I leave an image of my table of the section of purchase orders.
How could I adapt that function so that it does not make the count if it has a dash or the subtraction sign "-" that is shown when it does not have a command.
This is my Datatables code
$(document).ready(function(){
var table = $('#servicios').DataTable({
processing: true,
serverSider: true,
ordering: true,
"pageLength": 50,
"lengthMenu": [[5,10,50,-1], [5,10,50,"All"]],
"order": [[ 1, "asc" ]],
"autoWidth": false,
"language":{
"url": "//cdn.datatables.net/plug-ins/1.10.21/i18n/Spanish.json"
}
});
var contador = table.rows().count();
$("#counta").text((+contador));
//Counter of the column of purchase orders
var contador_oc = table.column(24).rows().count();
$("#counta_oc").text((+contador));
});
I would be very grateful if you help me to solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataTables具有a
repard() API,基本上是同名JavaScript功能的包装器。
您可以使用它来计算您感兴趣的相关值 - 例如:
请注意,在上述功能中使用
0
的使用,将计数器的初始值设置为零。这意味着a
(“上一个值”)以0和b
(“当前值”)开头,从列数据中的第一个值开始。有关更多语法详细信息,请参见。
这是一个演示,我在其中计算年龄不是“ 22”的记录数:
当您运行此演示时,它会将
54
打印到控制台,因为在57个记录中,有54个年龄不是22
。DataTables has a
reduce()
function as part of its API, which is basically a wrapper around the JavaScript function of the same name.You can use this to count the relevant values you are interested in - for example:
Note the use of
0
in the above function, to set the initial value of our counter to zero. This means thata
(the "previous value") starts with 0 andb
(the "current value") starts with the first value in the column data.For more syntax details, see the JavaScript documentation.
Here is a demo where I count the number of records where the age is not "22":
when you run this demo it prints
54
to the console, as there are 54 out of 57 records where the age is not22
.