Grid Search control not working

Hi,

I tried this codes that l found on your documentation 'Search on each key stroke' but it is not working. My grid search control is not working especially when loaded from the server. Kindly assist.

https://stackblitz.com/edit/angular-kqu7vy-rmhdpx?file=app.component.ts,app.component.html


6 Replies

PS Pavithra Subramaniyam Syncfusion Team September 1, 2022 05:13 AM UTC

Hi Charles,


Thanks for contacting Syncfusion support.


In the provided sample we could see that you have used the Grid reference inside the “created” event but missed setting the “#grid” attribute to the Grid Html definition which causes the script error. After adding the reference properly, the “Search on each Keystroke”  is working fine in the provided sample. Please refer to the below code example and sample link for more information.


// missed part

<ejs-grid #grid [dataSource]="data" [toolbar]="toolbarOptions" (created)="created($event)">

  . . .

</ejs-grid>

 


Sample: https://stackblitz.com/edit/angular-kqu7vy-nnbphz?file=app.component.ts,app.component.html


Note: In the above sample, the used WebAPI endpoint did not handle the “Search” action on the server side. So, it will return all the data while searching. This sample is given as an example only.


So please ensure that you have added "#grid" to your original sample. If you still facing the issue, please share the below details for validation.


  1. Share your Grid original Grid code
  2. Share the created event handler code
  3. Is there any script error?
  4. Is search request on each key stroke sent to the server?
  5. Have you handled the “Search” action in the API endpoint?


Regards,

Pavithra S



CH Charles September 1, 2022 08:18 PM UTC

Hi Pavithra,

When i press a key from the keyboard to search then this error appears (at the yellow background color spot) in the CustomerController 'System.NullReferenceException: 'Object reference not set to an instance of an object.'

Kindly assist.


<div class="control-section">

<div id="action-description">

<h5>

<code>Customer Listcode>

h5>

div>

<ejs-grid #grid [dataSource]="data" [toolbar]='toolbarOptions' (created)='created($event)' allowGrouping="true" allowPaging="true"

[pageSettings]="pageSettings" allowSorting="true" (actionFailure)="actionFailure($event)">

<e-columns>

<e-column field="CustomerId" headerText="ID" width="70" [isPrimaryKey]="true"> e-column>

<e-column field="CustomerName" headerText="Customer" width="150"> e-column>

<e-column field="CustomerSegment" headerText="Segment" width="120"> e-column>

e-columns>

ejs-grid>

div>


import { Component, OnInit, ViewChild } from '@angular/core';

import { EditService, PageService, ToolbarItems, CommandColumnService, CommandModel, GridComponent, EditSettingsModel } from '@syncfusion/ej2-angular-grids';

import { DataManager, UrlAdaptor } from '@syncfusion/ej2-data';

import { Internationalization } from '@syncfusion/ej2-base';


let instance: Internationalization = new Internationalization();


@Component({

selector: 'app-customer-list',

templateUrl: './customer-list.component.html',

styleUrls: ['./customer-list.component.css']

})


export class CustomerListComponent implements OnInit {

public editOptions: EditSettingsModel;

public toolbarOptions: ToolbarItems[];

public pageSettings: Object;

public data: DataManager;

@ViewChild('grid', { static: false })

public grid: GridComponent;


public dataManager: DataManager = new DataManager({

url: 'customer/UrlDatasource',

adaptor: new UrlAdaptor()

});


public ngOnInit(): void {

this.data = this.dataManager;

this.pageSettings = { pageSize: 5 };

this.toolbarOptions = ['Search'];

}


created(): void {

document.getElementById(this.grid.element.id + "_searchbar").addEventListener('keyup', () => {

this.grid.search((event.target as HTMLInputElement).value)

});

}


actionFailure(e) {

debugger;

}

}


using Microsoft.AspNetCore.Mvc;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using Syncfusion.EJ2.Base;

using japPRO19.Models;

using System.Collections;

namespace japPRO19.Controllers

{

public class customerController : Controller

{

private readonly bhfdbContext _context;

public customerController(bhfdbContext context)

{

_context = context;

}

public IActionResult Index()

{

return View();

}

public IActionResult Privacy()

{

return View();

}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

public IActionResult UrlDatasource([FromBody] DataManagerRequest dm)

{

IEnumerable DataSource = _context.Customer.ToList();

DataOperations operation = new DataOperations();

if (dm.Search != null && dm.Search.Count > 0)

{

DataSource = operation.PerformSearching(DataSource, dm.Search); //Search

}

if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting

{

DataSource = operation.PerformSorting(DataSource, dm.Sorted);

}

if (dm.Where != null && dm.Where.Count > 0) //Filtering

{

DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);

}

int count = DataSource.Cast().Count();

if (dm.Skip != 0)

{

DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging

}

if (dm.Take != 0)

{

DataSource = operation.PerformTake(DataSource, dm.Take);

}

return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);

}

Regards

Charles





PS Pavithra Subramaniyam Syncfusion Team September 2, 2022 12:51 PM UTC

Hi Charles,


We have prepared a sample as per the given code details, but it is working fine at our end. Please refer to the attached video and sample for more information.


To validate further please share the below details that will be helpful for us to provide a better solution as early as possible.


  1. Share the Syncfusion package version
  2. Share the “Syncfusion.EJ2. AspNet.Core” dll version
  3. Share the video demo of the issue reproducing
  4. Share an issue reproducible sample if possible


Regards,

Pavithra S


Attachment: GRidSearch_5c57db55.zip


PS Pavithra Subramaniyam Syncfusion Team September 2, 2022 12:52 PM UTC

Hi Charles,


Please refer to the attached demo link.


Regards,

Pavithra S


Attachment: demo_7268f529.zip


CH Charles September 5, 2022 10:15 PM UTC

Hi Pavithra,

My grid search is working fine when i changed (created)='created($event)'  to  (created)='created()'. Now l'm using  the tab control for my grids which loads data from the database fine, but Grid search is no longer working. Pls assist.

https://stackblitz.com/edit/angular-kqu7vy-rmhdpx?file=app.component.ts,app.component.html


Regards

Charles



PS Pavithra Subramaniyam Syncfusion Team September 6, 2022 09:18 AM UTC

Hi Charles,


While checking the given sample, a search request is sent for each keystroke in the search bar properly. Also, when we connect this sample with the active server URL it is working fine.




So please provide an issue reproducible sample with a proper URL that returns data to the grid component and a video demo that will be helpful for us to validate the issue and provide a better solution.


Regards,

Pavithra S


Loader.
Up arrow icon