2014-05-23 3 views
1

Laravel 4의 Chumper 's Data 테이블을 사용하여 테이블에 클래스 또는 ID를 추가하여 CSS 및 JS를 추가 할 수있는 방법은 없지만 그물 검색은 시도했지만 아무도 나에게 직접적인 대답을 제공하지 않습니다. 여기클래스 또는 ID를 Chumper Data Table에 추가하는 방법은 무엇입니까?

내 (작업) 코드 :

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를 추가 준비 기능

에 다음 <div id="salesdiv">

{{ HTML::script('js/dataTable/jquery.datatable.js') }} 
<?php echo HTML::flash(); ?> 
{{ Datatable::table() 
->addColumn('PA','Total Sales','%','Sales Count') 
->setUrl('api/getSales') 
->render(); 
}} 

을 포장하기

<script type="text/javascript"> 
$(document).ready(function() { 
$("#salesdiv table").addClass("salesTable"); 
}); 
0

단일 테이블의 경우이 시도 : ID 사용을위한

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(); 

setId('test1')

그렇지 않으면 u는 패키지 구성 파일 (응용 프로그램/설정/패키지/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 

도움이 되길 바랍니다.

관련 문제