Hi everyone, I'm currently working on a grid which is dynamically built and I'm experiencing some weird behaviour.
I'll try to do my best to explain it clearly, starting from the code of the grid:
<kendo-grid
[kendoGridBinding]="kgData"
[sortable]="true"
[pageable]="true"
[pageSize]="5"
>
<!-- BUTTONS -->
<ng-template kendoGridToolbarTemplate>
<button kendoGridAddCommand>Aggiungi record</button>
<button class="k-button">
Salva
</button>
</ng-template>
<!-- HEADERS -->
<kendo-grid-column *ngFor="let col of columnInfoArray" [field]="col.fieldname" [title]="col.description" [hidden]="col.fieldname === 'id'">
<ng-template
kendoGridCellTemplate
let-dataItem>
<!--! NUMBER -->
<!--
decimals: do not allow the user to type , and . when focused
format n0: do not put commas when the input is not focused
-->
<kendo-numerictextbox
*ngIf="col.configtype === 'int'"
kendoGridFocusable
[decimals]="0"
format="n0"
[value]="dataItem[col.fieldname]"
(valueChange)="kgUpdateValue(col.fieldname,dataItem,$event)"
></kendo-numerictextbox>
<!--! SELECT -->
<!--
[data]: the array of options, textField and valueField access the properties of the objects contained inside the array
[value]: gets the default value based on the fieldname and the value
-->
<kendo-dropdownlist
*ngIf="col.configtype === 'combo'"
kendoGridFocusable
[data]='kgSelectOptions[col.fieldname]'
textField='label'
valueField='value'
[value]='kgGetDefaultOption(col.fieldname,dataItem[col.fieldname])'
(valueChange)="kgUpdateValue(col.fieldname,dataItem,$event.value)"
></kendo-dropdownlist>
<!--! CHECKBOX -->
<input
*ngIf="col.configtype === 'bool'"
kendoGridFocusable
type="checkbox"
kendoCheckBox
(change)="kgUpdateValueEvent(col.fieldname,dataItem,$event)"
/>
<!--! STRING -->
<input
*ngIf="col.configtype === 'string'"
kendoGridFocusable
(change)="kgUpdateValueEvent(col.fieldname,dataItem,$event)"/>
</ng-template>
</kendo-grid-column>
</kendo-grid>
columnInfoArray is an array of objects like this: (of course with different values every time)
{
idfield: 1,
description: "Widget",
fieldname: "idwidget",
mandatory: true,
actionget: "widget",
configtype: "combo",
deleted: false,
filter: false
}
This tells the code the "type" of input I'm expecting, like a select box, a number, a textarea, a checkbox etc etc.
NOTE: despite I'm talking about inputs, the table isn't inside any form and forms aren't needed to get the job done.
The actionget, when present, is just a string that will be concatenated to a link and it'll get an array of objects that will look like:
{
label: 'Some text',
value: 1
}
There are two things that I don't understand
- inside the kendo-dropdownlist you can see the function kgGetDefaultOption. Inside this function I have put a console.log of a counter that starts from 0 and gets incresed every time the function is called: my kgData consists of 7 records, and I have two columns with configtype == 'combo'. I was expecting for the counter to be 14, but I get 89 instead. Also, the function is called every time I change page on the pagination bar. Why does that happen?
- if I check the checkbox on row 1 of page 1, every checkbox on row1 of other pages is checked as well (I'm providing a GIF that shows what I mean)
Unfortunately I can't provide a StackBlitz (the API calls that get the data don't work on it). I hope this is enough for you to help me, else I will provide more info.
PS: even if that esulates from the main question, if you think something can be improved for what I need, let me know! This is the very first time I'm using Kendo grid and to be honest I found the documentation really difficult to understand so I might've missed something.