How to bookmark a Primeng date checkbox?

131 Views Asked by At

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);
      }
    );
  }
1

There are 1 best solutions below

0
On

on your datatable definition, add a [(selection)]="selectedLanguages" property. on your component definition, add a variable called selectedLanguages: Language[] = []; In your getLanguage function, use a forEach on your this.userLanguage and check to see if it is marked active, if it is, push the language to the this.selectedLanguage variable. Be sure to set the this.selectedLanguages = [] as one of the first things on your getLanguage call

For an example of using selections, see the selections subsection of the datatable component Showcase showing selections