Kendo UI Grid Row Template - templates

I had a problem on how to apply row Template data binding into it. I not sure what is the syntax to do so. I am using server binding mode. Below is my code
#(Html.Kendo().Grid((IEnumerable<IcmsViewModel.LookupView>)ViewData["LookupView"]) // Bind the grid to the Model property of the view
.Name("Grid")
.CellAction(cell =>
{
if (cell.DataItem.Active == false)
{
cell.HtmlAttributes["style"] = "background-color: red";
}
}
)
.Columns(columns =>
{
columns.Bound(p => p.LookupValue).ClientTemplate(" ").Title("Short Name").Width(300);
columns.Bound(p => p.Description).Width(300);
columns.Bound(p => p.Active).Width(300);
columns.Command(command => { command.Edit(); command.Destroy(); });
})
**.RowTemplate(rows =>
"<tr><td>Testing</td>" +
"<td colspan=\"2\"><input type=\"button\" name=\"ClickMe\" value=\"ClickMe\" onclick=\"javascript:window.open(('/Test/ViewTest'), 'ViewTest', 'height=' + (window.screen.height - 100) + ',width=200,left=' + (window.screen.width - 250) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');\"/></td>" +
"<td>Name</td></tr>"
)**
.ToolBar(commands => commands.Create())
.Groupable()
.Pageable()
.Sortable()
//.Filterable()
.Scrollable(x => x.Height(600))
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Server()
.Model(model => { model.Id(p => p.Id); model.Field(p => p.Id).Editable(false); })
.Create(create => create.Action("CreateLookup", "Icms"))
.Read(read => read.Action("Lookup", "Icms"))
.Update(update => update.Action("UpdateLookup", "Icms"))
.Destroy(destroy => destroy.Action("Destroy", "Sample"))
)
)
Currently I hard code the value in the row template, how can I bind it with the data in database, if i want to apply the row template.
Example
.RowTemplate(rows =>
"p.LookupValue" +
"" +
"p.Description"
)
Please help me on this as I am new to kendo UI. Thanks a lot.

Why don't you use Template on the column definition :
.Columns(columns =>
{
columns.Bound(p => p.LookupValue)
.Template(#<text>#item.LookupValue #item.Description</text>).Title("Short Name").Width(300);
columns.Bound(p => p.Active).Width(300);
columns.Command(command => { command.Edit(); command.Destroy(); });
})

Related

Call to a member function store() on null on Livewire

I'm new to Livewire and I faced this problem Call to a member function store() on null I don't know how to make the store() function not work when I don't send a file! graduation_certificate it is nullable.
Database file
public function up()
{
Schema::create('user_trainees', function(Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('region_id')->unsigned();
$table->integer('city_id')->unsigned();
$table->integer('university_id')->unsigned();
$table->integer('department_id')->unsigned();
$table->string('major', 150);
$table->bigInteger('student_number')->nullable();
$table->float('gpa');
$table->enum('gpa_type', array('4', '5'));
$table->enum('training_date', array('firstsemester', 'secondsemester', 'thirdsemester', 'summersemester'))->nullable();
$table->integer('training_hours')->nullable();
$table->integer('graduation_year')->nullable();
$table->enum('academic_degree', array('bachelor', 'diploma'));
$table->string('graduation_certificate', 200)->nullable();
$table->string('academic_transaction', 200);
$table->string('cv', 200);
$table->tinyInteger('is_graduate');
$table->timestamps();
$table->softDeletes();
});
}
blade file
<x-form.label label="وثيقة التخرج" name="graduation_certificate" />
<div class="flex">
<input type="file" wire:model="graduation_certificate" name="graduation_certificate"
id="graduation_certificate"
class="px-8 py-12 border-2 border-dashed rounded-md dark:border-gray-700 dark:text-gray-400 dark:bg-gray-800">
</div>
livewire class
public function submit()
{
$user_uni = User::create([
'name' => "{$this->firstName} {$this->lastName}",
'type_id' => $this->userType,
'email' => $this->email,
'password' => bcrypt($this->password),
'gender' => $this->gender,
'mobile' => $this->mobile,
'is_active' => 1,
]);
UserTrainee::create([
'user_id' => $user_uni->id,
'region_id' => $this->region,
'city_id' => $this->city,
'university_id' => $this->university,
'department_id' => $this->department,
'major' => $this->major,
'student_number' => $this->studentNumber,
'gpa' => $this->gpa,
'gpa_type' => $this->gpa_type,
'training_date' => $this->training_date,
'training_hours' => $this->trainingHours,
'graduation_year' => $this->graduation_year,
'academic_degree' => $this->academic_degree,
'graduation_certificate' => $this->graduation_certificate->store('files', 'public'),
'academic_transaction' => $this->academic_transaction->store('files', 'public'),
'cv' => $this->cv->store('files', 'public'),
'is_graduate' => $this->traineeType,
]);
}
You don't conditionally store the files, meaning that even if you haven't uploaded something (meaning its NULL), you attempt to store it. Just wrap some conditions around it,
// ...
'graduation_certificate' => $this->graduation_certificate ? $this->graduation_certificate->store('files', 'public') : null,
'academic_transaction' => $this->academic_transaction ? $this->academic_transaction->store('files', 'public') : null,
'cv' => $this->cv ? $this->cv->store('files', 'public') : null,
// ...
you have to make variable of cv like you made for graduation_certificate, cv is getting NULL that's why you are facing this error

CakePHP 3.x - save not work in associate table

I have below table structure.
Mandator table
class MandatorTable extends Table
{
public function initialize(array $config)
{
$this->table('mandators');
$this->belongsToMany('Seminar', [
'foreignKey' => 'mandator_id',
'targetForeignKey' => 'seminar_id',
'joinTable' => 'mandators_seminars'
]);
}
}
Semiar table
class SeminarTable extends Table
{
public function initialize(array $config)
{
$this->table('seminars');
$this->belongsToMany('Mandator', [
'foreignKey' => 'seminar_id',
'targetForeignKey' => 'mandator_id',
'joinTable' => 'mandators_seminars'
]);
}
}
both table are belong to 'mandators_seminars' table
mandator_id, seminar_id
When I save data it's save in seminar table but not in 'mandators_seminars' table
Query
$seminartable = $this->Seminar->newEntity();
$this->request->data['mandator'][0] = 1;
$seminardata = $this->Seminar->patchEntity($seminartable, $this->request->data);
$this->Seminar->save($seminardata)
Request data
Array
(
[bookable] => test
[released] => aaa
[linkable] => bb
[name] => ccc
[internalnote] => ddd
[abstract] => ttt
[description] => ddd
[Category] => 14
[mandator] => Array
(
[0] => 1
)
[mandator_owner_id] => 1
)
Look you have two table Mandator and Similar as singular , but your connecting table is plural. Firstly check this. If there is still a problem check this CakePHP Through Association
As you can see your association should be like this:
$this->belongsToMany('Mandator', [
'foreignKey' => 'seminar_id',
'targetForeignKey' => 'mandator_id',
'through' => 'PluginName.MandatorsSeminars'
'joinTable' => 'mandators_seminars',
'className' => 'PluginName.Mandator'
]);
And one more tip: table should be called as plural.

OpenCart 3.0.2.0 - how to change sort order of search results & disable search in descriptions?

OpenCart 3.0.2.0 + Journal2 theme.
Problem: when using the search function, the results are sorted by "Default" sort order.
How can I change it to sort by "Name A-Z" (ascending)?
I've found a couple of solutions on SO, but they relate to OC 2.x, not 3.x, and they didn't work when I tried to implement them.
Also, as a bonus, if anyone knows how to disable the "Search in product descriptions" by default, I would really appreciate it.
For sort by "Name A-Z" (ascending)
Got to this path
catalog/controller/product/product.php
change code
Original Code
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
Change Only else part
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'pd.name';
}
For disable the "Search in product descriptions with 2 way.
Solution 1
remove or hide descriptions checkbox, check image below
Solution 2
Got to this path
catalog/controller/product/search.php
Original Code
$filter_data = array(
'filter_name' => $search,
'filter_tag' => $tag,
'filter_description' => $description,
'filter_category_id' => $category_id,
'filter_sub_category' => $sub_category,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);
Change only one line remove it or comment it.
$filter_data = array(
'filter_name' => $search,
'filter_tag' => $tag,
/*'filter_description' => $description,*/
'filter_category_id' => $category_id,
'filter_sub_category' => $sub_category,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);

how to add two product in opencart?

How to add two products . For example I added product1 . I want to split that product1 into product with media and product1 without media. Quantity are same .
In the product list it has to show in two different entries . Below is the code for adding product. now it is taking only one ..
$this->data[$key] = array(
'key' => $key,
'product_id' => $product_query->row['product_id'],
'name' => $product_query->row['name'],
'model' => $product_query->row['model'],
'shipping' => $product_query->row['shipping'],
'image' => $product_query->row['image'],
'option' => $option_data,
'download' => $download_data,
'quantity' => $quantity,
'minimum' => $product_query->row['minimum'],
'subtract' => $product_query->row['subtract'],
'stock' => $stock,
'price' => ($price + $option_price),
'total' => ($price + $option_price) * $quantity,
'reward' => $reward * $quantity,
'points' => ($product_query->row['points'] ? ($product_query->row['points'] + $option_points) * $quantity : 0),
'tax_class_id' => $product_query->row['tax_class_id'],
'weight' => ($product_query->row['weight'] + $option_weight) * $quantity,
'weight_class_id' => $product_query->row['weight_class_id'],
'length' => $product_query->row['length'],
'width' => $product_query->row['width'],
'height' => $product_query->row['height'],
'length_class_id' => $product_query->row['length_class_id'],
'recurring' => $recurring
);

Symfony2: PHPUnit Testing-> #dataProvider sends no multipleArray

I make UnitTesting for my application.
I have a save saveArticleIds() Method and I wrote a testing for it -> testSaveArticelIds(). I have an dataProvider articelIdsArray() whith a multiple array. The function need that array exact like this.
/**
*
* #dataProvider articleIdsArray
*
*/
public function testSavearticleIds($articleIds) {
$articleIdObjekt = new ArticleIdHandler();
$result = $articleIdObjekt->saveArticleIds($articleIds,false);
$this->assertTrue($result);
}
public function articleIdsArray() {
return array(
array(
10552 => 10552,
14314 => 14314,
21034 => 21034,
22739 => 22739,
34568 => 34568,
34572 => 34572,
35401 => 35401,
38292 => 38292,
55141 => 55141,
161764 => 161764,
181589 => 181589
)
);
}
When I run my test, I get this Error:
There was 1 error: 1) My\Bundle\ArticleBundle\Tests\Article\ArticleIdHandlerTest::testSaveArticleIds
with data set #0 (10552, 14314, 21034, 22739, 34568, 34572, 35401, 38292, 55141, 161764, 181589)
Invalid argument supplied for foreach()
Why does it show the array like I have no keys in the array? I need the array exact like in my dataProvider! Any idea?? THANKS A LOT FOR YOU HELP!!!
maybe try this:
public function articleIdsArray()
{
return
array(
array(
array(
10552 => 10552,
14314 => 14314,
21034 => 21034,
22739 => 22739,
34568 => 34568,
34572 => 34572,
35401 => 35401,
38292 => 38292,
55141 => 55141,
161764 => 161764,
181589 => 181589
)
)
);
}
The reason is that the first level of the array nesting is the set of data provided for each round of tests, the second level represents the arguments provided to testSavearticleIds, in the same order as in the parameter list of the function (in your example there is only one argument), the last level is just the test array itself.
Hope this helps...
Try this :
/**
* #dataProvider articleIdsArray
*/
public function testSavearticleIds($articleIds)
{
$articleIdObjekt = new ArticleIdHandler();
$result = $articleIdObjekt->saveArticleIds($articleIds,false);
$this->assertTrue($result);
}
public function articleIdsArray()
{
return array(
'scenario_one' => 10552,
'scenario_two' => 14314,
...,
);
}
You doesn't need to use #dataProvider in your example.
Define your method like this
public function getArticleIdsArray() {
return array(
10552 => 10552,
14314 => 14314,
21034 => 21034,
22739 => 22739,
34568 => 34568,
34572 => 34572,
35401 => 35401,
38292 => 38292,
55141 => 55141,
161764 => 161764,
181589 => 181589
);
}
and use it in your test
public function testSavearticleIds($articleIds) {
$articleIdObjekt = new ArticleIdHandler();
$result = $articleIdObjekt->saveArticleIds($this->getArticleIdsArray(),false);
$this->assertTrue($result);
}