Hi community, I am using primeng and I show in a table records that come from a database, I want to check my checkbox according to the response of the database, if the language is active I should load the check in true but I do not know how to access for mark it
<p-dataTable [value]="userLanguage" name="userLang" dataKey="key">
<p-column [style]="{'width':'38px'}" selectionMode="multiple"></p-column>
<p-column field="languageName" header="Idioma"></p-column>
<p-column field="languageId" header="Código"></p-column>
</p-dataTable>
Component:
// Obtener los idiomas del usuario
getLanguage(user){
this._userService.getLanguage(user).subscribe(
response => {
this.userLanguage = response.lstLOV;
},
error => {
console.log(<any>error);
}
);
}
on your datatable definition, add a
[(selection)]="selectedLanguages"
property. on your component definition, add a variable calledselectedLanguages: Language[] = [];
In yourgetLanguage
function, use aforEach
on yourthis.userLanguage
and check to see if it is marked active, if it is, push the language to thethis.selectedLanguage
variable. Be sure to set thethis.selectedLanguages = []
as one of the first things on yourgetLanguage
callFor an example of using selections, see the selections subsection of the datatable component Showcase showing selections