Skip to content

Commit

Permalink
add sort parameter to option component
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal committed Jan 10, 2024
1 parent b4b390b commit a10f6de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/components/table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ class TableComponent < ViewComponent::Base
renders_one :header, TableRowComponent
renders_many :rows, TableRowComponent

def initialize(id: '', stripped: true, borderless: false, layout_fixed: false, small_text: nil, outline: nil)
def initialize(id: '', stripped: true, borderless: false, layout_fixed: false, small_text: false, outline: false, sort: false)
super
@id = id
@stripped = stripped
@borderless = borderless
@layout_fixed = layout_fixed
@small_text = small_text
@outline = outline
@sort = sort
end

def stripped_class
Expand Down
15 changes: 8 additions & 7 deletions app/components/table_component/table_component.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
%table.table-content{id: @id ,class: stripped_class + ' ' + borderless_class + ' ' + layout_fixed_class + ' ' + mini_class + ' ' + outline_class}
%thead
= header
%tbody{id: "#{@id}_table_body"}
- rows.each do |row|
= row
= content
%div{'data-controller': 'table-component'}
%table.table-content{id: @id ,'data-sort': @sort.to_s,class: stripped_class + ' ' + borderless_class + ' ' + layout_fixed_class + ' ' + mini_class + ' ' + outline_class}
%thead
= header
%tbody{id: "#{@id}_table_body"}
- rows.each do |row|
= row
= content
19 changes: 19 additions & 0 deletions app/components/table_component/table_component_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Controller} from "@hotwired/stimulus"
import DataTable from 'datatables.net-dt';


// Connects to data-controller="table-component"
export default class extends Controller {
connect(){
let table_component
table_component = this.element.childNodes[1]
if (table_component.dataset.sort === 'true'){
let table = new DataTable('#'+table_component.id, {
paging: false,
info: false,
searching: false,
autoWidth: true
});
}
}
}

0 comments on commit a10f6de

Please sign in to comment.