@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...'), '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, ]) @php // reset variables for Laravel 8 support $has_shadow = filter_var($has_shadow, FILTER_VALIDATE_BOOLEAN); $hasShadow = filter_var($hasShadow, FILTER_VALIDATE_BOOLEAN); $hover_effect = filter_var($hover_effect, FILTER_VALIDATE_BOOLEAN); $hoverEffect = filter_var($hoverEffect, FILTER_VALIDATE_BOOLEAN); $striped = filter_var($striped, FILTER_VALIDATE_BOOLEAN); $compact = filter_var($compact, FILTER_VALIDATE_BOOLEAN); $divided = filter_var($divided, FILTER_VALIDATE_BOOLEAN); $searchable = filter_var($searchable, FILTER_VALIDATE_BOOLEAN); $uppercasing = filter_var($uppercasing, FILTER_VALIDATE_BOOLEAN); $celled = filter_var($celled, FILTER_VALIDATE_BOOLEAN); $selectable = filter_var($selectable, FILTER_VALIDATE_BOOLEAN); $checkable = filter_var($checkable, FILTER_VALIDATE_BOOLEAN); $transparent = filter_var($transparent, FILTER_VALIDATE_BOOLEAN); $message_as_empty_state = filter_var($message_as_empty_state, FILTER_VALIDATE_BOOLEAN); if ($hasShadow) $has_shadow = $hasShadow; if (!$hoverEffect) $hover_effect = $hoverEffect; $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 = []; $can_group = false; if (!is_null($data)) { $data = (!is_array($data)) ? json_decode(str_replace('"', '"', $data), true) : $data; $total_records = count($data); $table_headings = ($total_records > 0) ? array_keys((array) $data[0]) : []; if(!empty($exclude_columns)) { $table_headings = array_filter($table_headings, function($column) use ( $exclude_columns) { if(!in_array($column, $exclude_columns)) return $column; }); } if( !empty($include_columns) ) { $table_headings = explode(',', str_replace(' ','', $include_columns)); } 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); } } } @endphp
@if($searchable)
@endif @if(is_null($data)) @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 @foreach($table_headings as $th) @endforeach @if( !empty($action_icons)) @endif @if($total_records > 0) @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) @foreach($table_headings as $th) @if($th !== $groupby) @endif @endforeach @endforeach @endforeach @else @foreach($data as $row) @foreach($table_headings as $th) @endforeach @endforeach @endif @else @endif @endif
{{ str_replace('_', ' ', $column_aliases[$th] ?? $th ) }}{{$actions_title}}
{{ $group_heading }}
{!! $row[$th] !!}
{!! $row[$th] !!}
@if($message_as_empty_state) @else {{ $no_data_message }} @endif
@if($selectable) @once @endonce @endif @if($checkable) @once @endonce @endif