2016-04-25 68 views

回答

2

我的理解是,你要添加在你的数据线断裂,这样的事情,

enter image description here

在功能栏我传递一个数组,其每个项目显示在一个单独的行使用<br>

为此,您可以创建自定义转换器,

http://www.jquery-bootgrid.com/Documentation#converters

初始化BootGrid表

var dt = $('#myTable').bootgrid({ 
    //.......... Other Options 
    converters: { 
    listDisplay: { 
     from: function(value) { 
     return value; 
     }, 
     to: function(value) { 

    // Here you can customise value - I have an Array which I join using <br> 

     value.sort(); 
     value = value.join("<br/>"); 
     return value; 
     } 
    } 
    } 
}); 

然后你具有在该表HTML做的是设置在列的数据类型的标题

<table id="myTable"> 
     <thead> 
     <tr> 
      <th data-column-id="Id" data-visible="false" data-identifier="true" data-type="numeric">Id</th> 

      <th data-column-id="SelectedFeaturesNames" data-type="listDisplay">Features</th> 

<!-- Note the data-type on the Features <th> is listDisplay --> 

     </tr> 
     </thead> 
     <tbody></tbody> 
    </table> 
+0

你在哪里数组发送到功能?在'​​'标签里面? 非常感谢您的回答 –

+0

@JeremiasAraujo您使用Ajax来加载数据吗?我通过Ajax加载数据,并且数组位于Json对象内部 –

+0

我做到了!不,我不使用Ajax。数据使用PHP(laravel blade)加载。 我在value.sort()之前加了'value = JSON.parse(value);'将接收到的json转换为js数组。 –

0

当初帮着你可以创建转换器使用该方法工作?

是@达伍德阿旺!它的工作对我来说

PHP:

<td> 
    <?php 
     $test = ['b', 'a', 'c']; 
     echo json_encode($test); 
    ?> 
</td> 

JS:

to: function(value) { 
    value = JSON.parse(value); //convert received json to js array. 
    value.sort(); 
    value = value.join("<br/>"); 
    return value; 
} 
相关问题