1.0.2 • Published 5 months ago

ngx-search-bar-fz v1.0.2

Weekly downloads
-
License
-
Repository
github
Last release
5 months ago

Ngx Search Bar

Installation

To install this library, run:

$ npm install ngx-search-bar-fz --save

and then from your Angular AppModule:

import { BrowserModule } from "@angular/platform-browser"
import { NgModule } from "@angular/core"

import { AppComponent } from "./app.component"

// Import your library
import { DATA_FOR_SEARCH_BAR, NgxSearchBarModule } from "ngx-search-bar-fz"

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,

    // Specify your library as an import
    NgxSearchBarModule,
  ],
  providers: [
    {
      provide: NGX_SEARCH_BAR_DATA,
      useValue: {
        BASE_URL: environment.serverBar,
        OPTIONS: {
          classContainerFilter: "main-style",
          fnScrollTop: () => {
            window.scrollTo(0, 0)
          },
          stickyTop: "55px",
        },
        OPTIONS_PAGINATE: {
          fnGetLength: (arg: any) => {
            return arg.data.total
          },
        },
      },
    },
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

Usage in templates is as simple as:

<ngx-search-bar
  [isChangeUrl]="false"
  nameInputSearch="name"
  placeholder="Search products"
  title="Products"
  [autoInit]="true"
  (data)="getData($event)"
  [isBarExpand]="false"
  maxWidth="50%"
  [isSticky]="true"
  path="products-admin/products">
  <!-- Optional filters -->
  <ngx-search-bar-form-filter [filters]="formFilter" [withParamsClean]="false">
    <div [formGroup]="formFilter" class="gap-2 pt-2 grid md:grid-cols-2 w-full">
      <mat-form-field class="w-full" appearance="outline">
        <mat-label>ID</mat-label>
        <input matInput placeholder="#" formControlName="id" />
      </mat-form-field>
      <!-- More filters -->
    </div>
  </ngx-search-bar-form-filter>

  <!-- Optional buttons -->
  <ng-container buttons>
    <button class="!bg-orange-500 !text-white" mat-raised-button [routerLink]="['/admin-products/products/create']">
      <i class="fa-solid fa-plus"></i>
      Producto
    </button>
  </ng-container>

  <div class="overflow-auto p-2">
    <!-- render information -->
  </div>
  <!-- Optional paginator -->
  <ngx-search-bar-paginator></ngx-search-bar-paginator>
</ngx-search-bar>

NgxSearchBarComponent

Inputs

NameTypeDefaultDescription
placeholderstring'Search'Entry placeholder
titlestringnullComponent Title
pathstringsearchRoute for requests
isChangeUrlbooleanfalseIf the url should be changed when doing a search
autoInitbooleantrueIf it automatically starts searching
nameInputSearchstring'search'search Name of the search input to send to the backend
isBarExpandbooleanfalseIf it is an expanded bar
sizenumber1grow bar css
maxWidthstring'100%'maximum width of the bar
isStickybooleantruesi siempre es visible arriba(le afecta el top con el input stickyTop)
fnScrollTopFunctionnullFunction to return to the top by scrolling
notScrollbooleanfalseIf you scroll up with the function

Outputs

NamesTypeDescription
dataunknownEvent fired when data is received
loadingbooleanEvent fired when load state is changed

Slots

NameDescription
ngx-search-bar-form-filterComponent for filters
ngx-search-bar-paginatorComponent for paginator
buttonsButton slot next to filter button

Example img

Example

NgxSearchBarFormFilterComponent

Inputs

NameTypeDefaultDescription
filtersFormGroupis requiredfilter form that is sent to the backend
textBtnApplystring'Apply Filters'Apply button text
textBtnClosestring'Close Filters'Close button text
withParamsCleanbooleanfalseIf it should clean the params
classPanelstringnullClass for panel of filters

NgxSearchBarPaginatorComponent

Inputs

NameTypeDefaultDescription
fnGetLengthFunctionnullFunction that returns the length of the data
fnGetPageFunctionnullFunction that returns the current page