2014-05-23 29 views
1

如何在Laravel 4上使用Chumper的數據表添加類或ID,這樣我就可以在其上添加CSS和JS,我嘗試搜索網絡,但是沒有一個給出我直接的答案。如何在跳線數據表上添加類或ID?

這裏是我的(工作)代碼:

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

我想有沒有別的辦法,但手動添加類/ ID使用JavaScript,我有包

{{ 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"); 
}); 
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')

否則ü可以設置包的配置文件(應用程序/配置/包/ 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 

我希望這會有所幫助