symfony - Omines 数据表和列宽
问题描述
我尝试将 Omines 数据表包与 symfony (4) 一起使用,但我无法强制列宽...我已经看过这个页面 https://github.com/omines/datatables-bundle/issues/71 所以我试过了建议的解决方案,但这就像我什么都没做:我所有的列都有相同的宽度。
我忘了什么吗?
这是我的控制器:
public function actionList2(Request $request, DataTableFactory $dataTableFactory): Response
{
$options = [
'fixedHeader' => false,
'serverSide' => false,
'processing' => true,
'searching' => true,
'autoWidth' => false,
'columnFilter' => 'both',
'pageLength' => null,
'paging' => false,
];
$table = $dataTableFactory->create($options)
->add('actCod', TextColumn::class, ['label' => 'Code', 'searchable' => true, 'filter' => ['templateHTML' => 'datatables/Filter/text.html.twig', 'placeholder' => null]])
->add('actLib', TextColumn::class, ['label' => 'Libellé', 'searchable' => true, 'filter' => ['templateHTML' => 'datatables/Filter/text.html.twig', 'placeholder' => null]])
->add('actIdMere', TextColumn::class, ['label' => 'Action mère', 'searchable' => true, 'filter' => ['templateHTML' => 'datatables/Filter/text.html.twig', 'placeholder' => null]])
->add('actDatCmd', DateTimeColumn::class, ['label' => 'Commande', 'searchable' => true, 'filter' => ['templateHTML' => 'datatables/Filter/text.html.twig', 'placeholder' => null]])
->add('actDatMep', DateTimeColumn::class, ['label' => 'MEP', 'searchable' => true, 'filter' => ['templateHTML' => 'datatables/Filter/text.html.twig', 'placeholder' => null]])
->add('actUsrCre', TextColumn::class, ['label' => 'User Cre', 'searchable' => true, 'filter' => ['templateHTML' => 'datatables/Filter/text.html.twig', 'placeholder' => null]])
->add('actDatCre', DateTimeColumn::class, ['label' => 'Date Cre', 'searchable' => true, 'filter' => ['templateHTML' => 'datatables/Filter/text.html.twig', 'placeholder' => null]])
->add('actDatMod', DateTimeColumn::class, ['label' => 'Date Mod', 'searchable' => true, 'filter' => ['templateHTML' => 'datatables/Filter/text.html.twig', 'placeholder' => null]])
->createAdapter(ORMAdapter::class, ['entity' => V8Action::class
])
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
return $this->render('list2.html.twig', ['datatable' => $table]);
}
还有我的树枝...
{# /templates/list.html.twig #}
{% extends 'base.html.twig' %}
{% block titre %}liste{% endblock%}
{% block stylesheets %}
{{ parent() }}
{% endblock%}
{% block page_content %}
<a href="{{ path('home') }}">Home</a><br/>
<div id="list">Loading...</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
{{ encore_entry_script_tags('list2') }}
<script>
$(document).ready(function() {
$('#list').initDataTables({{ datatable_settings(datatable) }}
,{
columnDefs: [
{width: "30%", targets: [1]},
]
}
);
});
</script>
{% endblock %}
不使用列的宽度。
但是,我在 Omines datatable.js 中放置了一个 console.log :
root.html(data.template);
dt = $('table', root).DataTable(dtOpts);
console.log(dtOpts);
我可以在 dtOpts oO 中看到我的 columnDefs
解决方案
对我来说,我在我的树枝上做过这样的事情
table2 = $('#Dcfdatatables').initDataTables({{ datatable_settings(datatable) }} , {
"pageLength": 10,
dom: '<"top"lf>rt<"bottom"ip><"clear">',
"lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100,
columnDefs: [
{width: "4%", targets: 0, title:"<input type='checkbox' id='select_all' name='select_all'>"},
{width: "6%", targets: 1},
{width: "13%", targets: 2},
{width: "7%", targets: 3},
{width: "26%", targets: 4},
{width: "22%", targets: 5},
{width: "12%", targets: 6},
{width: "10%", targets: 7},
],initComplete: function(){
...
}
为我工作。
推荐阅读
- arm - 手臂皮层 a/r/m 编号约定的解释
- embedded - 如何在通过 HTTP 向 Azure IoT Hub 发送消息之间将 BG96 置于省电模式
- vba - 有没有办法在不打开文件的情况下提取访问模块?
- mysql - 在不同的列中排列电影的标题
- entity-framework-6 - 为什么 EF 搜索 NULL 返回 0 结果
- c - 使用'temp'数组在C中水平反射(翻转)图像
- typescript - 如何键入属性和值都来自其他类型的对象
- javascript - Vuex 在页面刷新时没有保持 currentUser 状态
- virtualhost - VirtualHost Alias 使用“/myapp/”加载/重定向,但没有斜杠“/myapp”的错误
- r - 按组计算数据集中各个列的计数和平均值