Below is my code for mvcgrid. My model contains properties Name, ProductCode, AvgWaight.
I want to add Column for ProductCode 2 times. But at runtime argument exception is thrown as "Column 'ProductCode ' already exist in the grid"
#Html.Grid(Model).Columns(columns =>
{
columns.Add(c => c.Name).Titled("Product Name ").SetWidth(200).Sortable(true).Filterable(true);
columns.Add(c => c.ProductCode).Titled("Product Code").SetWidth(200).Sortable(true).Filterable(true);
columns.Add(c => c.AvgWeight).Titled(" Avg. Weight").SetWidth(300).Sortable(true).Filterable(true);
}).WithPaging(5)
How to add same column multiple times, with different titles.
thank you in advance
Do it this way, it worked for me.
#Html.Grid(Model).Columns(columns =>
{
columns.Add(c => c.Name).Titled("Product Name").SetWidth(200).Sortable(true).Filterable(true);
columns.Add(c => c.ProductCode).Titled("Product Code").SetWidth(200).Sortable(true).Filterable(true);
columns.Add(c => c.ProductCode, "Duplicate Column").Titled("Product Code").SetWidth(200).Sortable(true).Filterable(true);
}
Related
i've some problem with my code.
$id = DB::table('sn_project_details')->insertGetId([
'emp_name' => $request->emp_name,
'emp_id' => $request->emp_id,
'department' => $request->department,
'submit_date' => $request->submit_date,
'total_amount' => $request->total_amount,
'project_tittle' => $request->project_tittle,
'project_desc' => $request->project_desc,
'scope' => $request->scope,
'file' => $request->file
]);
//Update Table
\DB::table('sn_project_details')
->where('project_id', $id)
->update(['doc_ref' => "ID_",$request->scope,"_",$id]);
return redirect('/user')
I want to update column doc_ref with example value ID_Scope_220,
ID_ its fixed value. Scope from textbox scope. 220 from #emp_id.
but when i execute this code, update query not working properly.
can someone help? thx
use dot instead of comma
->update(['doc_ref' => "ID_".$request->scope."_".$emp_id]);
Iam trying and not finding a way to load the value from a field and generate a select_from_array based on its range.
For example:
I have 2 select box
Brand -> loads -> Model (using backpack field types, and its working good)
`'type' => 'select2_from_ajax',
'name' => 'camera_model_id',
'entity' => 'camera_model',
'attribute' => 'name',
'data_source' => url('camera-brands'),
'placeholder' => 'Selecione o Modelo',
'minimum_input_length' => 0,
'dependencies' => ['camera_brand_id'],`
But, after the user selects this last selectBox, I need that another field was modified
`'name' => 'channel',
'label' => "Canal da Câmera",
'type' => 'select2_from_array',
'options' => ['' => '',
'01' => '01',
'02' => '02', ...`
So, the options could be filled with the maximum of the field I registered in the Model field database.
Is it possible? or maybe another approach to achieve the solution?
Thanks in advance!
To have an input that depends on the value of another input, you can make both your fields select2_from_ajax.
That way:
you will have the value of all inputs in the controller (the controller that returns the ajax results; then you can return a filtered set of results depending on how the form is filled so far - CategoryController::index() in the documentation example);
you can use the "dependencies" attribute on the selec2_from_ajax fields, so that when one field is reset, both are;
I hope the answer helps someone. Cheers!
I'm working on the bug where one screen has a grid that contains a column showing numbers, but when I try to filter it, it has "contains" option.
When I type 0, I'm getting an error.
I need to filter that column as a number not as a string.
This is the fragment of the code:
columns.Bound(x => x.DebitAmount).Title("Debit").Width(300).ClientTemplate("#=kendo.toString(DebitAmount,'c') #").ClientFooterTemplate("#=kendo.toString(sum,'c') #");
columns.Bound(x => x.CreditAmount).Title("Credit").Width(300).ClientTemplate("#=kendo.toString(CreditAmount,'c') #").ClientFooterTemplate("#=kendo.toString(sum,'c') #");
..................
.Filterable(ftb => ftb.Mode(GridFilterMode.Menu)
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains")
.IsEqualTo("EqualTo")
.IsNotEqualTo("NotEqualTo")
.IsEmpty("Empty")))
.Operators(operators => operators
.ForNumber(str => str.Clear()
.IsEqualTo("EqualTo")
.IsGreaterThan("GreaterThan")
.IsLessThan("LessThan")
)).Messages(m => m.IsFalse(" False "))
.Messages(m => m.IsTrue("True ")))
The model declares those fields as decimal
This is the generated part of the screen:
Another screen has another filterable grid with an Amount field. All the options are declared the same way, but that screen's filter for the Amount field does not include "contains" option when displayed.
This is the code:
columns.Bound(c => c.Amount).Title("Amount").ClientTemplate("#= kendo.toString(Amount,'c')#").Width("120px");
......................
.Filterable(ftb => ftb.Mode(GridFilterMode.Menu)
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains")
.IsEqualTo("EqualTo")
.IsNotEqualTo("NotEqualTo")
.IsEmpty("Empty")))
.Operators(operators => operators
.ForNumber(str => str.Clear()
.IsEqualTo("EqualTo")
.IsGreaterThan("GreaterThan")
.IsLessThan("LessThan")
)))
This is the part of the screen:
Everything seems the same (except of messages part) when defining the filter operations, but somehow, on the first screen, the "contains" operation is included and on the second is not.
What am I missing?
I have found the solution here: How can I force Kendo Grid to use a numeric filter on a column
I had to add the following conversion logic when defining the data source:
.Model(c => { c.Field<decimal>(d => d.DebitAmount); })
.Model(c => { c.Field<decimal>(d => d.CreditAmount); })
.Model(c => { c.Field<DateTime>(d => d.RequestedDate); })
I am using laravel backpack for my one project. I am stuck in one place where in the list of data the description column showing limited words in the column. I want to show full description in list column itself.
$this->crud->addColumn([
'label' => "Message",
'type' => 'text',
'name' => 'message'
]);
You should be able to do that using 'limit' => 20000. Here's this field's definition from the docs:
[
'name' => 'name', // The db column name
'label' => "Tag Name", // Table column heading
// 'prefix' => "Name: ",
// 'suffix' => "(user)",
// 'limit' => 120, // character limit; default is 80;
],
Hope it helps. Cheers!
I have tried to get total cost in sales order report but without success. I can see the related data in the "sales_order_aggregated_created" and "sales_order_aggregated_updated" tables in database but unable to see total cost of orders. The data is being managed through app/code/core/Mage/Sales/Model/Resource/Order/collection.php
Please help if any one have idea to get the same value.
Finally I have done with the same. I have made corrections in three files to get the total cost field in sales order report. First of all copy this three core files to local folder.
1.Add total cost app/code/local/Mage/Sales/Model/Resource/Report/Order/Createdat.php in columns array around line number 95
'total_base_cost' => new Zend_Db_Expr('SUM(oi.total_base_cost)')
Dont forget to add same column (total_base_cost) in sales_order_aggregated_created table in databse. Now the $columns would be as below:
$columns = array(
// convert dates from UTC to current admin timezone
'period' => $periodExpr,
'store_id' => 'o.store_id',
'order_status' => 'o.status',
'orders_count' => new Zend_Db_Expr('COUNT(o.entity_id)'),
'total_qty_ordered' => new Zend_Db_Expr('SUM(oi.total_qty_ordered)'),
'total_base_cost' => new Zend_Db_Expr('SUM(oi.total_base_cost)'),
'total_qty_invoiced' => new Zend_Db_Expr('SUM(oi.total_qty_invoiced)'),
'total_income_amount' => new Zend_Db_Expr(
sprintf('SUM((%s - %s) * %s)',
$adapter->getIfNullSql('o.base_grand_total', 0),
$adapter->getIfNullSql('o.base_total_canceled',0),
$adapter->getIfNullSql('o.base_to_global_rate',0)
)
),
and add same column in $cols array to get the value from sales/order_item table around line number 204
'total_base_cost' => new Zend_Db_Expr('SUM(base_cost)')
now $cols array is:
$cols = array(
'order_id' => 'order_id',
'total_qty_ordered' => new Zend_Db_Expr("SUM(qty_ordered - {$qtyCanceledExpr})"),
'total_base_cost' => new Zend_Db_Expr('SUM(base_cost)'),
'total_qty_invoiced' => new Zend_Db_Expr('SUM(qty_invoiced)'),
);
2. Add same column in app/code/local/Mage/Sales/Model/Resource/Report/Order/Collection.php arround line 87
'total_base_cost' => 'SUM(total_base_cost)',
now $this->_selected array will be as below:
$this->_selectedColumns = array(
'period' => $this->_periodFormat,
'orders_count' => 'SUM(orders_count)',
'total_qty_ordered' => 'SUM(total_qty_ordered)',
'total_base_cost' => 'SUM(total_base_cost)',
'total_qty_invoiced' => 'SUM(total_qty_invoiced)',
'total_income_amount' => 'SUM(total_income_amount)',
'total_revenue_amount' => 'SUM(total_revenue_amount)',
'total_profit_amount' => 'SUM(total_profit_amount)',
'total_invoiced_amount' => 'SUM(total_invoiced_amount)',
'total_canceled_amount' => 'SUM(total_canceled_amount)',
'total_paid_amount' => 'SUM(total_paid_amount)',
'total_refunded_amount' => 'SUM(total_refunded_amount)',
'total_tax_amount' => 'SUM(total_tax_amount)',
'total_tax_amount_actual' => 'SUM(total_tax_amount_actual)',
'total_shipping_amount' => 'SUM(total_shipping_amount)',
'total_shipping_amount_actual' => 'SUM(total_shipping_amount_actual)',
'total_discount_amount' => 'SUM(total_discount_amount)',
'total_discount_amount_actual' => 'SUM(total_discount_amount_actual)',
);
3. Final display the column in sales order report grid by adding the same column in the file app/code/local/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php
$this->addColumn('total_base_cost', array(
'header' => Mage::helper('sales')->__('Cost'),
'type' => 'currency',
'currency_code' => $currencyCode,
'index' => 'total_base_cost',
'total' => 'sum',
'sortable' => false,
'rate' => $rate,
));
It may help someone else who wants to add the same column.