如何使用 JS 数据表将默认值设置为字段
How to set default value to field using JS DataTables?
我正在使用JS数据表插件来呈现我的表,在某些行中,我在特定列中有NULL值:
我的数据集如下所示,表是在服务器端生成和呈现的。
Array
(
[0] => Array
(
[HostingID] => 1
[UserID] => 1
[HostingDomain] => reasda.hrt
[Coupon] => coupon1
)
[1] => Array
(
[HostingID] => 2
[UserID] => 1
[HostingDomain] => asdasd.hr
[Coupon] =>
)
[2] => Array
(
[HostingID] => 3
[UserID] => 1
[HostingDomain] => asdasds-hre
[Coupon] =>
)
)
我的JS很简单,因为一些默认设置是在包含的文件中初始化的。
<script type="text/javascript">
jQuery(document).ready( function ()
{
var table = jQuery('#tableActiveHostingServicesList').removeClass('hidden').DataTable( );
table.draw();
jQuery('#tableLoading').addClass('hidden');
});
</script>
这是我的观点部分:
<table id="tableActiveHostingServicesList" class="table table-list hidden">
<thead>
<tr>
<th>First column</th>
<th>Second column</th>
<th>Third column</th>
</tr>
</thead>
<tbody>
{foreach from=$activeservices item=activeservice}
<tr>
<td class="text-center">{$activeservice.HostingDomain}</td>
<td class="text-center">{$activeservice.Coupon}</span></td>
<td class="text-center">
<a href="" class="btn btn-block btn-info">
Reedem!
</a>
</td>
</tr>
{/foreach}
</tbody>
</table>
您需要使用 render
属性来定义将显示的内容。 更改初始化代码,以便在显示列值之前使用 render 检查 null。 在此示例中,如果列值为 null,则会显示连字符:
var table = jQuery('#tableActiveHostingServicesList').removeClass('hidden').DataTable({
'columns': [
{
// HostingID
'render': function (data, type, full, meta) {
if(full[0] != null){
return full[0];
}else{
return '-';
}
},
// UserID
'render': function (data, type, full, meta) {
if(full[1] != null){
return full[1];
}else{
return '-';
}
},
... etc
});
相关文章:
- 而循环只设置php中输入字段中的第一个值
- Extjs图表:动态设置字段
- 正在设置字段和'带有'陈述
- mailto:未在 GroupWise 8 消息中正确设置字段
- JavaScripts,AJAX,PHP:获取json字符串后无法设置字段值
- 使用 JQuery 重新设置字段值
- jQuery - 在通过加载函数加载操作页面时在操作页面中设置字段值
- 如何在高位图表中设置字段名
- 在Lotus Notes Web窗体中设置字段的JavaScript
- 从内部对象javascript设置字段值
- 如何在像这样的javascript对象中设置字段
- 是否有一种方法可以更新或设置字段,就像upsert对文档所做的那样
- 设置字段在不同的框架从javascript
- javascript:设置字段值并提交表单
- React Redux-如何在应用程序状态中设置字段
- 在 extjs 或 getCount() 的存储中动态设置字段在模型中给出 0
- CRM 2011 onChange 事件处理程序在 JavaScript 设置字段时未触发
- 我如何使用javascript在输入选择(HTML)中设置字段
- 如何设置字段的需求级别
- 我设置字段值w/ javascript, onchange未触发.可选择的解决方案