即時通訊使用Zend和Datatables(jQuery插件)。我有一個表像:將列添加到數據表
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="display" id="customerTable">
<thead>
<tr>
<th><?php $this->trans('ID') ?></th>
<th><?php $this->trans('Name') ?></th>
<th><?php $this->trans('Comment') ?></th>
<th><?php $this->trans('Options') ?></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th><?php $this->trans('ID') ?></th>
<th><?php $this->trans('Name') ?></th>
<th><?php $this->trans('Comment') ?></th>
<th><?php $this->trans('Options') ?></th>
</tr>
</tfoot>
</table>
我創建我的數組這樣的:
public function jsonAction() {
$this->_helper->layout->disableLayout();
$albums = new Application_Model_DbTable_Customers();
$albums = $albums->fetchAll()->toArray();
foreach($albums as $entry) {
$x[] = array($entry['id'], $entry['name'], $entry['comment'], '');
}
$this->view->json = json_encode(array("aaData" => $x));
}
正如你看到的,即時通訊創造,我編碼爲JSON之後的數組。對於選項字段,我只是添加了''。
在選項字段,我想要一些編輯圖標等等。我怎樣才能到,很容易?不知怎的,這個解決方案似乎並不像它那麼好。
我在想是這樣的,預定義我的表沒有選項字段。所以我的JSON匹配它。那麼,這樣做:
$('#myTable').datatables({
'optionsColumn' : {path/to/icon.jpg, /url/it/calls,
second icon etc}
});
或者只是像addColumn(HTML),它被重複每個條目。我不想將HTML放入我的動作中,然後通過JS糟糕的方式添加它。
感謝
你有可能發佈你的JSON輸出嗎?這將使我們有可能進行調試。 – bpeterson76