Is there any way for a custom column to know whether it's displayed in a table or div? #1179
Unanswered
fronbow
asked this question in
Q&A (Help)
Replies: 3 comments 2 replies
-
Hey @fronbow Can you explain with some screenshots? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
-
Hello every In excel we have =sum(a1:a20) but in backpack how get the total of all row ? crud->setModel('App\Models\BorrowAccount'); $this->crud->setRoute(config('backpack.base.route_prefix') . '/borrow-account'); $this->crud->setEntityNameStrings('Borrow Account', 'Borrow Accounts'); } protected function setupListOperation() { $this->crud->addColumns([ [ 'name' => 'borrower_name', 'label' => "Borrower Name", 'type' => "text", ], [ 'name' => 'loan_amount', 'label' => "Loan Amount", 'type' => "text", ], [ 'name' => 'loan_date', 'label' => "Loan Date", 'type' => "date", ], [ 'name' => 'total_paid', 'label' => "Total Paid", 'type' => "model_function", 'function_name' => 'getTotalPaidAmount', ], [ 'name' => 'total_remaining', 'label' => "Total Remain", 'type' => "model_function", 'function_name' => 'getTotalRemainingAmount', ], [ 'label' => "Branch", 'type' => "select", 'name' => 'branch_id', 'entity' => "branch", 'attribute' => "name", 'model' => "App\Models\Branch", ], [ 'label' => 'Project', 'type' => 'select', 'name' => 'project_id', 'entity' => 'project', 'attribute' => 'name', 'model' => 'App\Models\Project', ], [ 'name' => 'status', 'label' => "Status", 'type' => "select_from_array", 'options'=> trans('borrow_status'), ], ]); } protected function setupCreateOperation() { $this->crud->setCreateContentClass('col-md-10'); $this->crud->setEditContentClass('col-md-10'); $this->crud->setValidation(BorrowAccountRequest::class); $this->crud->addFields([ [ 'name' => 'borrower_name', 'label' => "Borrower Name", 'type' => "text", 'wrapperAttributes' => ['class' => 'form-group col-md-6'], ], [ 'name' => 'loan_amount', 'label' => "Loan Amount", 'type' => "number", 'wrapperAttributes' => ['class' => 'form-group col-md-3'], ], [ 'name' => 'loan_date', 'label' => "Loan Date", 'type' => "datetime_picker", 'datetime_picker_options' => [ 'format' => 'DD-MM-YYYY', 'language' => 'en', ], 'wrapperAttributes' => ['class' => 'form-group col-md-3'], ], [ 'label' => "Branch", 'type' => "select2", 'name' => 'branch_id', 'entity' => "branch", 'attribute' => "name", 'model' => "App\Models\Branch", 'options' => (function( $query ) { $employee = DB::table('employees')->where('user_id', Auth::id())->first(); if (!empty($employee)) { // Retrieve branches associated with the authenticated user's branch return $query->where('id', $employee->branch_id)->active()->get(); }else{ return $query->orderBy('name', 'ASC')->active()->get(); } }), 'wrapperAttributes' => [ 'class' => 'form-group col-md-6', ], ], [ 'label' => "Project", 'type' => "select2_from_ajax", 'name' => 'project_id', 'entity' => "project", 'attribute' => "name", 'data_source' => url('api/project'), 'method' => 'POST', 'placeholder' => 'Select a project', 'minimum_input_length' => 0, 'dependencies' => ['branch_id'], 'wrapperAttributes' => [ 'class' => 'form-group col-md-6', ], ], [ 'name' => 'repayment_schedule', 'label' => 'Repayment Schedule (if do not pay enter 0)', 'type' => 'table', 'entity_singular' => 'more repayment', // used on the "Add X" button 'columns' => [ 'installment_amounts' => 'Installment Amounts', 'description' => 'Installment Amount Description', 'amount_date' => 'Date', ], 'store_in' => 'repayment_schedule', 'wrapperAttributes' => ['class' => 'form-group col-md-12'], ], [ 'name' => 'purpose', 'label' => "Purpose", 'type' => "summernote", 'wrapperAttributes' => ['class' => 'form-group col-md-12'], 'options' => [ 'height' => 150, ], ], // [ // 'name' => 'status', // 'label' => "Borrow Status", // 'type' => "select_from_array", // 'options'=> trans('borrow_status'), // 'wrapperAttributes' => ['class' => 'form-group col-md-4'], // ], ]); } protected function setupUpdateOperation() { $this->setupCreateOperation(); } protected function setupShowOperation() { $this->crud->set('show.setFromDb', false); $this->crud->addColumns([ [ 'name' => 'borrower_name', 'label' => "Borrower Name", 'type' => "text", ], [ 'name' => 'loan_amount', 'label' => "Loan Amount", 'type' => "text", ], [ 'name' => 'loan_date', 'label' => "Loan Date", 'type' => "date", ], [ 'name' => 'repayment_schedule', 'label' => 'Repayment Schedule', 'type' => 'table', 'entity_singular' => 'more repayment', // used on the "Add X" button 'columns' => [ 'installment_amounts' => 'Installment Amounts', 'description' => 'Installment Amount Description', 'amount_date' => 'Date', ], 'store_in' => 'repayment_schedule', 'wrapperAttributes' => ['class' => 'form-group col-md-12'], ], [ 'name' => 'paid_amount', 'label' => "Total Paid Amount", 'type' => "model_function", 'function_name' => 'getTotalPaidAmount', ], [ 'name' => 'remaining_amount', 'label' => "Total Remaining Amount", 'type' => "model_function", 'function_name' => 'getTotalRemainingAmount', ], [ 'label' => "Branch", 'type' => "select", 'name' => 'branch_id', 'entity' => "branch", 'attribute' => "name", 'model' => "App\Models\Branch", ], [ 'label' => 'Project', 'type' => 'select', 'name' => 'project_id', 'entity' => 'project', 'attribute' => 'name', 'model' => 'App\Models\Project', ], [ 'name' => 'status', 'label' => "Status", 'type' => "select_from_array", 'options'=> trans('borrow_status'), ], [ 'name' => 'created_at', 'label' => "Created At", 'type' => "date", ], [ 'name' => 'updated_at', 'label' => "Updated At", 'type' => "date", ], [ 'name' => 'created_by', 'label' => "Created By", 'type' => "text", ], [ 'name' => 'updated_by', 'label' => "Updated By", 'type' => "text", ], ]); } public function afterSaved($request, $borrowAccount){ if(!$borrowAccount->wasRecentlyCreated){ $borrowAccount->temp_amount = $borrowAccount-> getTotalPaidAmount(); $borrowAccount->save(); } } public function afterUpdate($request, $borrowAccount) { $totalBorrowAmount = $borrowAccount->getTotalPaidAmount()- $borrowAccount->temp_amount; $budget = Budget::where('branch_id', $request->input('branch_id')) ->where('project_id', $request->input('project_id')) ->latest() ->first(); $remainingBudget = $budget->budget_amount + $budget->balance; if ($totalBorrowAmount <= $remainingBudget) { //$budget->budget_amount -=$totalExpenseAmount; $budget->balance -= $totalBorrowAmount; $budget->save(); }else{ \Log::error('Total borrow amount exceeds remaining budget.'); } $remain = $borrowAccount->getTotalRemainingAmount(); if($remain==0){ $borrowAccount->status = 0; $borrowAccount->save(); }else{ $borrowAccount->status = 1; $borrowAccount->save(); } } } ![Uploading 122789f9-8a4b-460a-9bbf-ae0444f9ce1a.jpeg…]() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All
As the title says, is there any way to check when in a custom column whether it's being used in a table or a div?
I have a custom column for sectioning my long records, in normal divs it works fine - displays as if it was a header type field by taking the whole row width. But if it's displayed in table view I would want the section label to span both columns with a bit of styling (no values).
Cheers for any help
:)
Beta Was this translation helpful? Give feedback.
All reactions