@props([ // your table headers in tags 'header' => '', // setting to true will result in a striped table 'striped' => config('bladewind.table.striped', false), // should the table with displayed with a drop-shadow effect 'has_shadow' => config('bladewind.table.has_shadow', false), 'hasShadow' => config('bladewind.table.has_shadow', false), // should the table have a border on all four sides 'has_border' => config('bladewind.table.has_border', false), // should the table have row dividers 'divided' => config('bladewind.table.divided', true), // if table has row dividers, how wide should they be // available value are regular, thin 'divider' => config('bladewind.table.divider', 'regular'), // should rows light up on hover 'hover_effect' => config('bladewind.table.hover_effect', true), 'hoverEffect' => config('bladewind.table.hover_effect', true), // should the rows be tighter together 'compact' => config('bladewind.table.compact', false), // provide a table name you can access via css 'name' => 'tbl-'.uniqid(), 'data' => null, 'exclude_columns' => null, 'include_columns' => null, 'action_icons' => null, 'groupby' => null, 'actions_title' => 'actions', 'column_aliases' => [], 'searchable' => config('bladewind.table.searchable', false), 'search_placeholder' => config('bladewind.table.search_placeholder', 'Search table below...'), 'search_field' => null, 'search_debounce' => 0, 'search_min_length' => 0, 'celled' => config('bladewind.table.celled', false), 'uppercasing' => config('bladewind.table.uppercasing', true), 'no_data_message' => config('bladewind.table.no_data_message', 'No records to display'), 'message_as_empty_state' => config('bladewind.table.message_as_empty_state', false), // parameters expected by the empty state component --------------- 'image' => asset('vendor/bladewind/images/empty-state.svg'), 'heading' => '', 'button_label' => '', 'show_image' => config('bladewind.table.show_image', true), 'onclick' => '', //------------------ end empty state parameters ------------------- 'selectable' => config('bladewind.table.selectable', false), 'checkable' => config('bladewind.table.checkable', false), 'transparent' => config('bladewind.table.transparent', false), 'selected_value' => null, 'sortable' => config('bladewind.table.sortable', false), 'sortable_columns' => [], 'paginated' => config('bladewind.table.paginated', false), 'pagination_style' => config('bladewind.table.pagination_style', 'arrows'), 'page_size' => config('bladewind.table.page_size', 25), 'show_row_numbers' => config('bladewind.table.show_row_numbers', false), 'show_total' => config('bladewind.table.show_total', true), 'show_page_number' => config('bladewind.table.show_page_number', true), 'show_total_pages' => config('bladewind.table.show_total_pages', false), 'default_page' => 1, 'total_label' => config('bladewind.table.total_label', 'Showing :a to :b of :c records'), 'limit' => null, 'layout' => 'auto', ]) @php // reset variables for Laravel 8 support $has_shadow = parseBladewindVariable($has_shadow); $hasShadow = parseBladewindVariable($hasShadow); $hover_effect = parseBladewindVariable($hover_effect); $hoverEffect = parseBladewindVariable($hoverEffect); $striped = parseBladewindVariable($striped); $compact = parseBladewindVariable($compact); $divided = parseBladewindVariable($divided); $searchable = parseBladewindVariable($searchable); $search_field = parseBladewindVariable($search_field, 'string'); $search_debounce = parseBladewindVariable($search_debounce, 'int'); $search_min_length = parseBladewindVariable($search_min_length, 'int'); $uppercasing = parseBladewindVariable($uppercasing); $celled = parseBladewindVariable($celled); $selectable = parseBladewindVariable($selectable); $checkable = parseBladewindVariable($checkable); $transparent = parseBladewindVariable($transparent); $paginated = parseBladewindVariable($paginated); $sortable = parseBladewindVariable($sortable); $page_size = parseBladewindVariable($page_size, 'int'); $message_as_empty_state = parseBladewindVariable($message_as_empty_state); $show_row_numbers = parseBladewindVariable($show_row_numbers); $show_total = parseBladewindVariable($show_total); $default_page = parseBladewindVariable($default_page, 'int'); if ($hasShadow) $has_shadow = $hasShadow; if (!$hoverEffect) $hover_effect = $hoverEffect; $name = preg_replace('/[\s-]/', '_', $name); $exclude_columns = !empty($exclude_columns) ? explode(',', str_replace(' ','', $exclude_columns)) : []; $action_icons = (!empty($action_icons)) ? ((is_array($action_icons)) ? $action_icons : json_decode(str_replace('"', '"', $action_icons), true)) : []; $column_aliases = (!empty($column_aliases)) ? ((is_array($column_aliases)) ? $column_aliases : json_decode(str_replace('"', '"', $column_aliases), true)) : []; $icons_array = $indices = []; $can_group = false; if (!is_null($data)) { $data = (!is_array($data)) ? json_decode(str_replace('"', '"', $data), true) : $data; $total_records = (!empty($limit)) ? $limit : count($data); $default_page = ($default_page > ceil($total_records/$page_size)) ? 1 : $default_page; $table_headings = $all_table_headings = ($total_records > 0) ? array_keys((array) $data[0]) : []; if( !empty($include_columns) ) { $exclude_columns = []; $table_headings = explode(',', str_replace(' ','', $include_columns)); } if($sortable){ $sortable_columns = empty($sortable_columns) ? $table_headings : explode(',', str_replace(' ','', $sortable_columns)); } // dd($sortable_columns); // Ensure each row in $data has a unique ID if (!in_array('id', $all_table_headings)){ foreach ($data as &$row){ $row['id'] = uniqid(); } } if(!empty($groupby) && in_array($groupby, $table_headings)) { $can_group = true; $unique_group_headings = array_unique(array_column($data, $groupby)); } // build action icons foreach ($action_icons as $action) { $action_array = explode('|',$action); $temp_actions_arr = []; foreach($action_array as $this_action){ $action_str_to_arr = explode(':', $this_action); $temp_actions_arr[trim($action_str_to_arr[0])] = trim($action_str_to_arr[1]); } $icons_array[] = $temp_actions_arr; } if(!function_exists('build_click')){ function build_click($click, $row_data){ return preg_replace_callback('/{\w+}/', function ($matches) use ($row_data) { foreach($matches as $match) { return $row_data[str_replace('}', '', str_replace('{', '', $match))]; } }, $click); } } if(!function_exists('pagination_row')){ function pagination_row($row_number, $page_size=25, $default_page=1): string { $row_id = uniqid(); $row_page = ($row_number < $page_size) ? 1 : ceil($row_number/$page_size); return sprintf("data-id=%s data-page=%s class=%s", $row_id, $row_page, ($row_page != $default_page ? 'hidden' : '')); } } } @endphp
@if($searchable)
@endif @if(is_null($data) || $layout == 'custom') @if(!empty($header)) {{ $header }} @endif {{ $slot }} @else @php // if there are no records, build the headings with $column_headings if the array exists $table_headings = ($total_records>0) ? $table_headings : (($column_aliases) ?? []); // when grouping rows, remove the heading for the column being grouped by if($can_group) { unset($table_headings[array_search($groupby, $table_headings)]); } @endphp @if($show_row_numbers) @endif @foreach($table_headings as $th) @if(empty($exclude_columns) || !in_array($th, $exclude_columns)) @php // get positions/indices of the fields to be displayed // use these indices to directly target data to display from $data $indices[] = $loop->index; @endphp @endif @endforeach @if(!empty($action_icons)) @endif @if($total_records > 0 && $layout == 'auto') @if($can_group) @foreach($unique_group_headings as $group_heading) @php $grouped_data = array_filter($data, function ($item) use ($group_heading, $groupby) { return $item[$groupby] === $group_heading; }); @endphp @foreach($grouped_data as $row) @php $row_id = $row['id']; @endphp @foreach($table_headings as $th) @if($th !== $groupby && in_array($loop->index, $indices)) @endif @endforeach @endforeach @endforeach @else @foreach($data as $row) @php $row_id = $row['id']; $row_page = (!$paginated || $loop->iteration < $page_size) ? 1 : ceil($loop->iteration/$page_size); @endphp @if(!empty($limit) && $loop->iteration > $limit) @break @endif @if($show_row_numbers) @endif @foreach($table_headings as $th) @if(in_array($loop->index, $indices)) @endif @endforeach @endforeach @endif @else @endif @endif
# {{ str_replace('_', ' ', $column_aliases[$th] ?? $th ) }} @if($sortable && in_array($th, $sortable_columns)) {{$actions_title}}
{{ $group_heading }}
{!! $row[$th] !!}
{{$loop->iteration}}{!! $row[$th] !!}
@if($message_as_empty_state) @else {{ $no_data_message }} @endif
@if($paginated && !empty($total_records)) @endif
@if($selectable) @once @endonce @endif @if($checkable) @once @endonce @endif @if($sortable) @once @endonce @endif