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

When I search for records, the operation does a filtering

Hi, I'm setting up a Grid with a search bar in the toolbar, using the UrlAdaptor. I am using all the operations that the grid has (search, filtering, ordering, paging).
The problem I have is that when I want to perform searches, in the ActionResult, the DataManagerRequest parameter has in Search = null and in Where it is what Search should have and an Exception occurs.

Here is my code

view:

@using Syncfusion.EJ2
@{
    ViewBag.Title = "Index";
    }
@{
    List<object> toolbarItems = new List<object>();
    toolbarItems.Add(new { text = "Agregar", tooltipText = "Agregar nuevo registro", prefixIcon = "e-add", id = "btnAgregar" });
    toolbarItems.Add("Edit");
    toolbarItems.Add("Delete");
    toolbarItems.Add("Update");
    toolbarItems.Add("Cancel");
    toolbarItems.Add("Search");
}

@(Html.EJS().Grid("CatPartesEquipo")
            .DataSource(dataManager => dataManager.Url(Url.Action("DataPartes", "CatPartesEquipo", new { area = "Catalogos" }, Request.Url.Scheme))
                .RemoveUrl(Url.Action("BajaConsumible", "CatPartesEquipo", new { area = "Catalogos" }, Request.Url.Scheme))
                .Adaptor("UrlAdaptor").CrossDomain(true))
             .ShowColumnMenu(true)
             .AllowFiltering(true)
             .AllowGrouping(true)
             .AllowMultiSorting(true)
             .AllowPaging(true)
             .AllowSorting(true)
             .Columns(c =>
             {
                 c.Field("SuministroCode").IsPrimaryKey(true).IsIdentity(true).HeaderText("Id").Width("50px").Add();
                                                                  c.Field("TipoSuministroCode").Width("130px").HeaderText("Tipo").ForeignKeyField("TipoSuministroCode").ForeignKeyValue("Descripcion")
.DataSource((IEnumerable<object>)ViewBag.tipo).Add();
                 
c.Field("NombreEquipoCode").HeaderText("Equipo").Width("130px").ForeignKeyField("NombreEquipoCode").ForeignKeyValue("Descripcion")
.DataSource((IEnumerable<Object>)ViewBag.nombreEquipo).Add();

            c.Field("MarcaCode").Width("130px").HeaderText("Marca").ForeignKeyField("MarcaCode").ForeignKeyValue("Descripcion")
.DataSource((IEnumerable<object>)ViewBag.marca).Add();
                 
c.Field("ModeloCode").Width("130px").HeaderText("Modelo").ForeignKeyField("ModeloCode").ForeignKeyValue("Descripcion")
DataSource((IEnumerable<object>)ViewBag.modelo).Add();
                
 c.Field("Descripcion").Width("150px").HeaderText("Descripcion").Add();
                 
c.Field("MarcaSuministroCode").Width("150px").HeaderText("Marca Suministro").Add();
                 c.Field("FamiliaSuministroCode").Width("130px").HeaderText("Familia").ForeignKeyField("FamiliaSuministroCode").ForeignKeyValue("FamiliaSuministro").DataSource((IEnumerable<object>)ViewBag.familia).Add();
                 
c.Field("Clave").Width("100px").Add();
                 
c.Field("NoParte").Width("100px").HeaderText("No. Parte").Add();
                
c.Field("Original").DisplayAsCheckBox(true).EditType("booleanedit").Type("boolean").Width("100px").Add();
                 
c.Field("UnidadCode").Width("100px").HeaderText("Unidad").ForeignKeyField("UnidadCode").ForeignKeyValue("Unidad")
.DataSource((IEnumerable<object>)ViewBag.unidad).Add();
                 
c.Field("PresentacionSuministroCode").Width("130px").HeaderText("Presentacion").ForeignKeyField("PresentacionSuministroCode")
.ForeignKeyValue("Presentacion").DataSource((IEnumerable<object>)ViewBag.presentacion).Add();
                 
c.Field("EstatusSuministroCode").Width("100px").HeaderText("Estatus").ForeignKeyField("EstatusSuminitroCode").ForeignKeyValue("EstatusConsumible")
.DataSource((IEnumerable<object>)ViewBag.estatusConsumible).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))
             .Locale("es-ES").Toolbar(toolbarItems).ToolbarClick("toolbarClick")
             .EditSettings(edit => { edit.AllowDeleting(true).AllowEditing(true); })
             .SearchSettings(s => { s.IgnoreCase(true); })
             .ActionBegin("begin")
             .Render()
)

server:
public ActionResult DataPartes(Syncfusion.EJ2.Base.DataManagerRequest dm)
        {
            IEnumerable<mehow.domain.catalogs.CatSuministros> x = _catService.GetConsumibles();
            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<mehow.domain.catalogs.CatSuministros>().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 hope you can help me. Thanks in advance

4 Replies

KM Kuralarasan Muthusamy Syncfusion Team June 5, 2019 02:59 PM UTC

Hi Juan, 
 
Thanks for contacting Syncfusion support. 
 
We would like to inform that currently our EJ2-DataManager do not have the support to search a foreignKeyValue.  We have already logged a feature task to provide Need to provide ForeignKeyValue search support in EJ2-DataManager. This feature will available in any of our upcoming Essential Studio release. Also, you can now track the current status of this feature request here, 

 
Regards,  
Kuralarasan M 



JC Juan Cruz June 5, 2019 03:54 PM UTC

Ok, I'll have to change the dataSource to not use ForeignKey.
So, the search will work if I do not have any field with ForeignKey?
I try to do the search with the "Detalles" field, but the problem that I describe occurs.

I will check if with the change made I have no problems.

Attachment: CapturaGRDSEARCH_951bcf00.rar


JC Juan Cruz June 5, 2019 11:50 PM UTC

I already made the changes and I no longer have problems. Just one question: How can I delete all the records in a grid with an external button? Works with grid.dataSource = null?


TS Thavasianand Sankaranarayanan Syncfusion Team June 6, 2019 01:40 PM UTC

Hi Juan, 

From your query we found that you want to delete all rows from the Grid by using external button click. But first we would like to inform that we need to select all the records from the Grid before perform the delete action. So we suggest to use persist checkbox selection Grid feature to select all page records from the Grid. After selecting the all records, you can call the deleteRecord method of the Grid delete all of the selected records. Please refer the following code snippet, 

<button id="btn" class="e-btn" onclick="btnClick()">Delete All Grid Records</button> 
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.datasource).SelectionSettings(sel => { sel.PersistSelection(true); }).AllowPaging(true).Columns(col => 
{ 
    col.Type("checkbox").Width("120").Add(); 
    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("100").Add(); 
}).EditSettings(edit => { edit.AllowDeleting(true); }).Render() 
 
<script type="text/javascript"> 
    function btnClick(e) { 
       var grid = document.getElementById("Grid").ej2_instances[0]; 
        grid.deleteRecord(); 
    } 
</script> 

Note: you must need to provide primaryKey to Grid to use persistSelection feature.  

If you do not want to select the Grid rows to achieve your requirement, then you can provide empty array to Grid dataSource in external button click event to remove all the rows from the Grid. Please refer the following code snippet, 

function btnClick1(e) { 
        var grid = document.getElementById("Grid").ej2_instances[0]; 
        grid.dataSource = []; 
    } 

We have prepared the sample for your reference and you can find that sample from the below link, 


Regards, 
Thavasianand S. 


Loader.
Live Chat Icon For mobile
Up arrow icon