3.0.0 • Published 4 months ago

@eqproject/eqp-select v3.0.0

Weekly downloads
50
License
MIT
Repository
-
Last release
4 months ago

Table of contents

Required

  • Angular Material installed and imported

Getting started

Step 1: Install eqp-select:

NPM

npm install --save @eqproject/eqp-select

Step 2: Import the EqpSelectModule and install :

import { EqpSelectModule } from '@eqproject/eqp-select';

@NgModule({
  declarations: [AppComponent],
  imports: [EqpSelectModule],
  bootstrap: [AppComponent]
})
export class AppModule {}

API

Inputs

InputTypeDefaultRequiredDescription
placeholderstring-noLabel shown as placeholder inside select.
enumDataany-noEnum property to use in order to create a key-value array.
enumDataToExcludeArray<any>-noArray of elements to exclude among those included inside the given Enum.
arrayDataArray<any>-noArray of objects that select will show. The structure can be {keyProperty: '', valueProperty: ''} or an array of primitive elements. In the second case, arrayKeyProperty must be ID and arrayValueProperty must be Label.
arrayKeyPropertystring-nostring that will be the key property. It must be ID if arrayData is an array of primitive elements
arrayValuePropertystring-nostring that will be the value property. It must be Label if arrayData is an array of primitive elements
ngModelOptionsany-noOptions to pass to ngModel.
ngModelInputany-noBinded property of object.
formGroupInputany-noFormGroup name, in case of formControlNameInput, that property need to be repeated for EVERY eqp-select used
formControlNameInputany-noformControlName defined in ts formGroup control
isRequiredbooleanfalsenoSet select as required.
isDisabledbooleanfalsenoDisable the select.
isMultiLanguagebooleanfalsenoIf true, see section and examples about use, if not interested in use, set to false or don't write it
multilanguagePrefixKeystring-noPrefix of the key used to translate the property.
isAlphabeticalOrderablebooleanfalsenoDefine if the datasource will be ordered.
suffixIconstring-noString containing the icon (mat-icon) that will appear after the label of the selected object(s).
prefixIconstring-noString containing the icon (mat-icon) that will appear before the label of the selected object(s).
isMultiSelectbooleanfalsenoDefine if the Select allows multiple selection.
showCancelButtonbooleantruenoProperty to define if the button to clear the selection is visible.
isSearchablebooleanfalsenoDefines if it's possible to type inside select and search among items.
noResultSearchTextstring'Nessun elemento trovato'noCustom text when filter returns empty result.
isReadonlybooleanfalsenoSet select as readonly.
isSearchWhileComposingbooleantruenoWhether items should be filtered while composition started.
appendToInputstring-noInput used when the select is contained inside a dialog or tab and there are visualization problems. Useful value: 'body'.
dropdownPositionauto \| top \| bottom \| auto-noSpecifies the position of the dropdown.
selectOnTabbooleantruenoSelect marked dropdown item using tab.
selectAllbooleanfalsenoAdd an option inside the dropdown that allows the user to select all the elements.
selectAllTextstring'Seleziona tutto'noText displayed in the select all option.
selectableGroupAsModelbooleanfalsenoIndicates whether to select all children or group itself.
clearAllTextstring'Elimina'noText displayed as tooltip when hovering the clear button.
customOptionTemplateRef<any>-noCustom template for the option inside the dropdown panel.
customLabelTemplateRef<any>-noCustom template for the selected item's label.
classstring-noClass useful to wrap Select.

N.B. One of EnumData or ArrayData is required

Outputs

OutputEvent argumentsRequiredDescription
(ngModelInputChange)any-Invoked when the value changes and the ngModelInput is binded. When items are grouped (selectAll) it returns the group 'exploded'.
(formControlChange)any-Invoked when the value changes and a form control is binded. When items are grouped (selectAll) it returns the group 'exploded'.

Reload data

When your datasource changes, you can update the datasource inside the select calling the function "reloadData", as follows:

  reload() {
    this.selectToReload.reloadData();
  }

It will work for both arrayData and enumData changes.

Use cases

Case 1: Select with arrayData and ngModelInput

Define selector in html for normal use

  <eqp-select 
    [arrayData]="dataSource" 
    [isSearchable]="true" 
    [(ngModelInput)]="selectWithArrayData" 
    placeholder="Seleziona elemento" 
    (ngModelInputChange)="selectChange($event)"
    [includeFullObject]="false" 
    [arrayKeyProperty]="'Key'"
    [arrayValueProperty]="'Description'">
  </eqp-select>

Define variables and functions in ts file

  dataSource : Array<{Key: string, Description: string}>;
  selectWithArrayData: any;
  
  ...

  selectChange(event) {
    // Body
  }

Case 2: Multi-select with enumData and form control

Define selector in HTML

    <eqp-select 
        [enumData]="testEnum" 
        [isMultiSelect]="true"
        placeholder="Seleziona elemento" 
        (formControlChange)="selectChange($event)"
        [formGroupInput]="formGroup"
        [formControlNameInput]="'selectWithEnumData'">
    </eqp-select>

Define variables and functions in ts file

  testEnum = TestEnum;
  formGroup: FormGroup;
  
  ...

  createForm() {
    this.formGroup = this.formBuilder.group({
      selectWithEnumData: []
    })
  }

  ...

  selectChange(event) {
    // Body
  }

Case 3: Multi-select with select all

Define selector in HTML

    <eqp-select 
        [enumData]="testEnum" 
        (formControlChange)="selectChange($event)"
        [formGroupInput]="formGroup"
        [formControlNameInput="'selectWithEnumDataAndSelectAll'"
        [isMultiSelect]="true"
        [selectAll]="true"
        [selectableGroupAsModel]="true"
        placeholder="Seleziona elemento"> 
    </eqp-select>

Define variables and functions in ts file

  testEnum = TestEnum;
  formGroup: FormGroup;
  
  ...

  createForm() {
    this.formGroup = this.formBuilder.group({
      selectWithEnumDataAndSelectAll: []
    })
  }

  ...

  selectChange(event) {
    // Body
  }

Multi-language

To use multilanguage, set to true the input boolean variable and pass a string that can be used to find the element inside the translation JSON

    <eqp-select 
        [enumData]="testEnum" 
        [isMultiSelect]="true"
        placeholder="Seleziona elemento" 
        (formControlChange)="selectChange($event)"
        [formGroupInput]="formGroup"
        [formControlNameInput]="'selectWithEnumData'"
        [isMultiLanguage]="true"
        [multilanguagePrefixKey]="'ENUMS.TEST.'">
    </eqp-select>

Then, where you set the language to use, like on login page or in navbar to switch language

    this.translateHelper.loadJsonLanguage("en", jsonObject);

Credits

This library has been developed by EqProject SRL, for more info contact: info@eqproject.it

3.0.0

4 months ago

2.5.1

4 months ago

2.5.0

4 months ago

2.1.3

4 months ago

2.0.4

10 months ago

2.1.2

6 months ago

2.1.1

6 months ago

2.1.0

6 months ago

2.0.3

11 months ago

2.0.2

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

0.4.7

2 years ago

0.4.5

2 years ago

0.4.6

2 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.3.9

3 years ago

0.4.0

3 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.0

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.0

4 years ago

0.1.1

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago