PHP:
foreach ($list as $key=>$row) { $json = json_decode($row['product_ids'], true); $str = ''; foreach ($json as $key2=>$value) { $name = \app\admin\model\product\ProductList::where(array('id'=>$value['id']))->column('productname')[0]; $price = \app\admin\model\product\ProductList::where(array('id'=>$value['id']))->column('price')[0]; $str .= '商品名稱:'.$name.','; $str .= '購買數量:'.$value['num'].'冊'.','; $str .= '商品單價:'.$price.','; } $str = mb_substr($str, 0, -1); $list[$key]['product_ids'] = $str; }
JS:
{field: 'product_ids', title: __('Product_ids'), operate: 'LIKE',formatter: function (value){ var arr = value.split(','); var html = ''; $.each(arr,function(index,values){ html += values+'<br/>'; }); return html; }},
單一字段自動換行:
{field: 'admin_id', title: __('負責人'), operate: 'LIKE',cellStyle: {css: {"max-width": "300px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}}, cellStyle: {css: {"max-width": "300px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}