gpt4 book ai didi

php - 带彩色按钮的 Laravel 查询

转载 作者:行者123 更新时间:2023-11-30 00:04:55 24 4
gpt4 key购买 nike

我是 Laravel 4 的新手。我这里有一个非常简单的问题。

我用这个来调用这个查询。

$users = DB::table('alumnos')->select(array('id', 'Nombre', 'Apellidos','Seccion','Grado','Preceptor','P1','P2','P3','P4','P5','P6','P7','P8'));
return Datatables::of($users)

我正在填充这样的表格:

  +--------+-----------+------------+
| Nombre | Apellidos | P1 |
+--------+-----------+------------+
|Nombre 1|Apellido1 | 0 |
|Nombre 1|Apellido1 | 1 |
|Nombre 1|Apellido1 | 0 |
|Nombre 1|Apellido1 | 1 |
|Nombre 1|Apellido1 | 1 |
|Nombre 1|Apellido1 | 1 |
+--------+-----------+------------+

该表使用 JavaScript 代码填充:

var oTable;
$(document).ready(function() {
oTable = $('#registros').dataTable( {
"sDom": "<l><f><r>t<i><p>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sSearch": "Search:",
"sLengthMenu": "_MENU_ records per page"
},
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "{{ URL::to('registrar/datadirectivos') }}"
});

$("#users_filter input").addClass("form-control inline-control input-sm");
$("#users_length select").addClass("form-control inline-control");
});

我想要做的是更改名为 Preceptoria 的最后一列,该列显示的按钮不是数字,而是动态颜色的按钮,具体取决于 1 为绿色按钮,0 为红色按钮。

最佳答案

我已经解决了。

我更改了 JavaScript 代码:

$(document).ready(function() {
oTable = $('#registros').dataTable( {
"sDom": "<l><f><r>t<i><p>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sSearch": "Search:",
"sLengthMenu": "_MENU_ records per page"
},"fnRowCallback": function( nRow, aData, iDisplayIndex,iDisplayIndexFull) {
$(nRow).children().each(function(index, td) {
if(index == 5 || index == 6 || index == 7 || index == 8 || index == 9 || index == 10 || index == 11 || index == 12) {
if ($(td).html() === "0") {
$(td).html("<button class='btn' style='background-color:#A8383B;'>P1</button>");
}
if ($(td).html() === "1") {
$(td).html("<button class='btn' style='background-color:#3C8D2F;'>P1</button>");
}
}
});
return nRow;
},
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "{{ URL::to('registrar/datadirectivos') }}"
});
$("#users_filter input").addClass("form-control inline-control input-sm");
$("#users_length select").addClass("form-control inline-control");
});

关于php - 带彩色按钮的 Laravel 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24657444/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com