如何在Laravel 4上使用Chumper的数据表在表上添加类或ID,这样我就可以在其上添加CSS和JS,我尝试搜索网络,但没有一个能给我直接答案。
这是我的(工作)代码:
public function getSales()
{
$sales = DB::table('tblsaleshistory')
->select('ordered_by',DB::raw('sum(salesTotal) as st, count(ordered_by) as sell'))
->groupBy('ordered_by');
return Datatable::query($sales)
->addColumn('Name',function($model)
{
$html = $model->ordered_by;
return $html;
})
->addColumn('data',function($model)
{
$salesTotal = $model->st;
return $salesTotal;
})
->addColumn('%',function($model)
{
$percentage = "<span id='pa-".$model->ordered_by."'>".($model->st/5000)*100 ."</span>";
return $percentage;
})
->addColumn('sell',function($model)
{
$sell = $model->sell;
return $sell;
})
->searchColumns(array('ordered_by','sell','st'))
->orderColumns('st')
->make();
}
在我看来:
{{ HTML::script('js/dataTable/jquery.datatable.js') }}
<?php echo HTML::flash(); ?>
{{ Datatable::table()
->addColumn('PA','Total Sales','%','Sales Count') // these are the column headings to be shown
->setUrl('api/getSales') // this is the route where data will be retrieved
->render();
}}
答案 0 :(得分:0)
我猜没有其他方法,但是要使用Javascript手动添加class / id,我必须包装
{{ HTML::script('js/dataTable/jquery.datatable.js') }}
<?php echo HTML::flash(); ?>
{{ Datatable::table()
->addColumn('PA','Total Sales','%','Sales Count')
->setUrl('api/getSales')
->render();
}}
然后使用<div id="salesdiv">
准备好功能
<script type="text/javascript">
$(document).ready(function() {
$("#salesdiv table").addClass("salesTable");
});
答案 1 :(得分:0)
对于单人表,试试这个:
Datatable::table()
->addColumn('PA','Total Sales','%','Sales Count')
->setUrl('api/getSales') // this is the route where data will be retrieved
->setClass('class1 class2 class3')
->render();
用于ID setId('test1')
否则你可以在包配置文件中设置(app / config / packages / chumper / config.php)
/*
|--------------------------------------------------------------------------
| Table class
|--------------------------------------------------------------------------
|
| Class(es) added to the table
| Supported: string
|
*/
'class' => 'class1 class2',
/*
|--------------------------------------------------------------------------
| Table ID
|--------------------------------------------------------------------------
|
| ID given to the table. Used for connecting the table and the Datatables
| jQuery plugin. If left empty a random ID will be generated.
| Supported: string
|
*/
'id' => 'test',
发布包配置文件你必须在终端上运行这个artisan命令
php artisan config:publish chumper/datatable
我希望这会有所帮助