We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

System.NullReferenceException when search in grid with URLAdaptor

Hello, I am creating a grid with URLAdaptor, adding a box to search in the toolbar. Sorting, paging, filtering and those actions are performed without problem, but in the search the exception is thrown. Here is my code

@{
    List<object> toolbarItems = new List<object>();
    toolbarItems.Add( "ExcelExport" );
    toolbarItems.Add("Search");
}
@(Html.EJS().Grid( "GridStudents" )
            .DataSource( dataManager => dataManager.Url( Url.Action( "DataGrid", "Grid", null, Request.Url.Scheme ) )
                 .Adaptor( "UrlAdaptor" ).CrossDomain( true ) )
            .ShowColumnMenu( true )
            .AllowFiltering( true )
            .AllowGrouping( true )
            .AllowMultiSorting( true )
            .AllowPaging( true )
            .AllowSorting( true )
            .AllowExcelExport( true )
            .Columns( c =>
            {
                c.Field( "Id" ).Width( 50 ).Add();
                c.Field( "Name" ).Add();
                c.Field( "Age" ).Width( 140 ).Add();
                c.Field( "School" ).Width( 150 ).Add();
                c.Field( "Enrollment" ).Width( 130 ).Add();               
                c.Field("Status").Visible(false).Add();
            } )
            .FilterSettings( f => f.Type( Syncfusion.EJ2.Grids.FilterType.Excel ) )
            .GroupSettings( g => g.ShowGroupedColumn( true ) )
            .PageSettings( p => p.PageSize( 15 ) )
            .SortSettings( s => s.AllowUnsort( true ) )
            .SearchSettings(s => { s.IgnoreCase(true); })
            .DataBound("autoFill")
            .Render()
)

c#

public ActionResult(Syncfusion.EJ2.Base.DataManagerRequest dm)
{
     IEnumerable<StudentModel> x = _service.ReadStudents().ToList();
                Syncfusion.EJ2.Base.DataOperations operations = new Syncfusion.EJ2.Base.DataOperations();
                if (dm.Search != null && dm.Search.Count > 0)
                {
                    x = operations.PerformSearching(x, dm.Search);  //Search
                }
                if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
                {
                    x = operations.PerformSorting(x, dm.Sorted);
                }
                if (dm.Where != null && dm.Where.Count > 0) //Filtering
                {
                    x = operations.PerformFiltering(x, dm.Where, dm.Where[0].Operator);
                }                
                var y = x.Cast<StudentModel>().Count();
                if (dm.Skip != 0)
                {
                    x = operations.PerformSkip(x, dm.Skip);   //Paging
                }
                if (dm.Take != 0)
                {
                    x = operations.PerformTake(x, dm.Take);
                }
                return Json(new { result=x, count=y}, JsonRequestBehavior.AllowGet);
}

I do not know if more code is necessary to configure the search.

I have another question: is it possible to change the size of the grid letter?
I hope you can help me. I thank you in advance

5 Replies

HJ Hariharan J V Syncfusion Team April 29, 2019 12:37 PM UTC

Hi Juan, 

Thanks for contacting Syncfusion support. 

Query #1:  but in the search the exception is thrown 

We have prepared the Grid sample with search option. But the reported issue was not reproduced at our end. So we have attached that sample with this update for your reference. Still, If you facing the same issue, please share the following details for further assistance, 

  1. Network tab response while perform the search action.
  2. In which line you have faced this issue in controller.
  3. Share the screenshot of this issue.
  4. If possible try to reproduce this issue in our sample and send back to us.
  5. Syncfusion package version.

Query #2: is it possible to change the size of the grid letter? 

We suggest to add the custom class to the Grid columns. After that you can add the custom style to that column cells by using that custom class. You can easily add this custom class to the Grid column by using CustomAttributes property of the Grid. Please refer the following code snippet, 

@Html.EJS().Grid("Grid").DataSource(ds => { ds.Url(Url.Action("UrlDataSource", "Home", "null", Request.Url.Scheme)).Adaptor("UrlAdaptor"); }).AllowFiltering(true).AllowMultiSorting(true).AllowSorting(true).AllowPaging(true).Columns(col => 
{ 
 
    col.Field("OrderID").HeaderText("Order ID").CustomAttributes(new { @class = "customcss" }).Width("100").Add(); 
 
}).SearchSettings(s => { s.IgnoreCase(true); }).Toolbar(new List<string>(){ "Search" }).Render() 
 
<style> 
    .customcss { 
        font-size: 25px !important; 
    } 
</style> 

Please refer the below sample for your both queries, 



Regards, 
Hariharan 



JC Juan Cruz replied to Hariharan J V April 29, 2019 04:03 PM UTC

Hi Juan, 

Thanks for contacting Syncfusion support. 

Query #1:  but in the search the exception is thrown 

We have prepared the Grid sample with search option. But the reported issue was not reproduced at our end. So we have attached that sample with this update for your reference. Still, If you facing the same issue, please share the following details for further assistance, 

  1. Network tab response while perform the search action.
  2. In which line you have faced this issue in controller.
  3. Share the screenshot of this issue.
  4. If possible try to reproduce this issue in our sample and send back to us.
  5. Syncfusion package version.

Query #2: is it possible to change the size of the grid letter? 

We suggest to add the custom class to the Grid columns. After that you can add the custom style to that column cells by using that custom class. You can easily add this custom class to the Grid column by using CustomAttributes property of the Grid. Please refer the following code snippet, 

@Html.EJS().Grid("Grid").DataSource(ds => { ds.Url(Url.Action("UrlDataSource", "Home", "null", Request.Url.Scheme)).Adaptor("UrlAdaptor"); }).AllowFiltering(true).AllowMultiSorting(true).AllowSorting(true).AllowPaging(true).Columns(col => 
{ 
 
    col.Field("OrderID").HeaderText("Order ID").CustomAttributes(new { @class = "customcss" }).Width("100").Add(); 
 
}).SearchSettings(s => { s.IgnoreCase(true); }).Toolbar(new List<string>(){ "Search" }).Render() 
 
<style> 
    .customcss { 
        font-size: 25px !important; 
    } 
</style> 

Please refer the below sample for your both queries, 



Regards, 
Hariharan 


I already reviewed the project they gave me and in this the search is done correctly, but in the project I am working on, it continues to mark error. I send you some screenshots

Attachment: grid_search_Exception_b980db3e.rar


HJ Hariharan J V Syncfusion Team April 30, 2019 09:47 AM UTC

Hi Juan, 

Thanks for the update. 

We suspect that some of the Grid column field names are not present in your controller data source (in here your data source variable name is “x”) or the Grid field names may have case mismatch with your controller data source. We can able to reproduce this issue in these two cases only. So please ensure these two cases in your project. 

You can ensure these two cases in your controller like as following screenshot, 

 
 

 
 

Still, If you facing the same issue please share the following details. This will help us to provide the solution as early as possible. 

  1. From your screenshot we found that you have provided “15” columns to Grid. But in your first update code snippet you have mentioned only six columns. So, please ensure whether the updated code is correct?
  2. Please share your full Grid code snippet.
  3. Please ensure Grid field names and controller data source object kes are in same case.
  4. How do you perform search action in the Grid (i.e by using default search toolbar item or any external search)?

Regards, 
Hariharan 



JC Juan Cruz April 30, 2019 05:03 PM UTC

First of all, I apologize for making a mistake by uploading the first piece of code here is my class that is used for the grid

The detail of the class that I am using is that they are many properties (almost 50) but I only use less than half. What I did to make it work is that I had to restrict the columns where I was going to look

.SearchSettings (s => {s.IgnoreCase (true) .Fields (new string [] {"Hospital", "ComputerNameDesc", "BrandDesc"});})

I thank you for your help




Attachment: respuesta_Grid_1059dff2.rar


HJ Hariharan J V Syncfusion Team May 2, 2019 12:25 PM UTC

Hi Juan, 
 
Thanks for your update.  
  
We are happy to hear that your issue has solved.  
   
Regards, 
Hariharan 


Loader.
Live Chat Icon For mobile
Up arrow icon