2011-03-27 5 views
1

내가 사용 클라이언트 측의 jQuery DataTables를 통해 실행 테이블편집/삭제하려면 행을 클릭하십시오.

$query = $this->expenses_model->expenses_table(); 

//gary's code went here 

$this->load->library('table'); 
$tmpl = array ('table_open' => '<table class="table">'); 
$this->table->set_template($tmpl); 

// gary added 'Edit' at end of array 

$this->table->set_heading('Date', 'Plant', 'Expense', 'Category', 'Notes'); 

//when using gary's code, changed $query below to $data 

$table['tab'] = $this->table->generate($query);  
$this->load->view('vw/exp/expenses_vw', $table, TRUE); 

을 생성하기 위해 CI를 사용하고

$(document).ready(function() { 
    /* Init DataTables */ 
    var oTable = $('.table').dataTable({ 
       "bJQueryUI": true, 
       "sScrollX": "", 
       "bSortClasses": false, 
       "aaSorting": [[0,'desc']], 
       "bAutoWidth": true, 
       "bInfo": true, 
       "sScrollY": "100%", 
       "sScrollX": "100%", 
       "bScrollCollapse": true, 
       "sPaginationType": "full_numbers", 
       "bRetrieve": true 
       });  
    }); 

질문 # 1 데이터베이스에서 각 레코드는 고유의 자동 증가 ID가 record_id 그것은 각 행에 전달되어야합니다. 그러나이 record_id 열은 프런트 엔드에 표시 할 수 없습니다 (즉, 숨길 필요가 있음). CI를 통해 어떻게해야합니까?

질문 # 2 사용자가 행을 클릭하고 편집/삭제할 양식이있는 팝업을 표시하려면 어떤 종류의 JS를 사용해야합니까?

도와 주셔서 감사합니다.

PS는 - 여기

function expenses_table() 
{ 
    $id = $this->tank_auth->get_user_id(); 

    $this->db->select('record_id, date_format(date, \'%c/%d/%Y\'), plant_name, concat(\'$ \', format(value_1, 2)), value_2, value_3', FALSE); 
    $this->db->from('data'); 
    $this->db->join('plants', 'plants.plant_id = data.plant_id_fk'); 
    $this->db->where('category_1', 'expenses'); 
    $this->db->where('data.id_fk', $id); 
    $this->db->order_by("date", "desc"); 
    $query = $this->db->get(); 

    return $query; 
} 

답변

2

1. 각각의 RECORD_ID을 기반으로 새 열 Edit

$this->table->set_heading('Date', 'Plant', 'Expense', 'Category', 'Notes', 'Edit'); 

2. 빌드 편집 링크를 추가 테이블 데이터를 생성 할 수있는 모델입니다 기록 및 숨기기 record_id

$data = array(); 

while ($row = $query->result_array()) 
{ 
    $anchor = '<a href="#" class="edit_record" record_id="' . $row['record_id'] . '">Edit</a>'; 

    // Hide the record_id in the table output 
    unset($row['record_id']); 

    // Let's add the link so we can edit this entry 
    $row[] = $anchor; 

    // Lets push the new row so it can be output 
    $data[] = $row; 

} 

$table['tab'] = $this->table->generate($data); 

3. jQuery를은 행과 상호 작용 :

$('a.edit_record').click(function() { 
var record_id = this.attr('record_id'); 

// Lets generate the magical lightbox here... 

}); 

는 HTML을 받아 들일 수 jQuery를 사용할 수 많은 라이트 플러그인이 있습니다. 요청을 처리하는 Ajax 컨트롤러를 만들고,이 모델을 사용하여 JSON에서 결과를 편집/삭제하고 결과를 반환하기 만하면된다. 녹색 @gary

jquery lightbox html (Google)

+0

- 응답에 대한 감사 - 내 업데이트를 위, 나는 테이블 데이터를 생성하는 데 사용하는 모델을 추가 참조하십시오 - 어떤 생각 방법 - 나는 while' 루프 또는 '사용하고 있지 않다 내 상황에서'unset'''record_id'? – pepe

+0

@gary green - 다른 문제는 'unset'이 열을 제거하지만'record_id'를 사용하여 각 행을 고유하게 만들 수 없다는 것입니다. – pepe

+0

실제로 필요한 것은 무엇입니까? 이제 각 행을 고유하게 만드는 것에 대해 이야기하고 있습니까? ... –

관련 문제