Help with foreign data on grid

Hello.
I'm developing an page where I have to list the users in database and I'm facing some issues.
1) I don't know how to bind one field with their corresponding row in Roles table.
This is my model (shorted for focus on the problem):
public class User
{
public Guid Id {get;set;}
public string UserName {get;set;}
public string FullName {get;set;}
public string PhoneNumber {get;set;}
public Guid RoleId {get;set;}
}
public class Role
{
public Guid Id {get;set;}
public string Name {get;set;}
}
My table definition looks as follows:



and the Javascript code:
<% var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();%>
var roleData = <%=serializer.Serialize(RoleList)%>
function OnLoad(args) {
this.model.dataSource.adaptor = new ej.ForeignKeyAdaptor([{ foreignKeyField: "Id", foreignKeyValue: "RoleId", dataSource: roleData }], "JsonAdaptor");
}
I've verified that the RoleList property is loaded.
The grid has a WebMethodAdapter DataManager to fill the data and followed the example onhttps://help.syncfusion.com/aspnet/grid/data-adaptors?cs-save-lang=1&cs-lang=js#foreign-key-adaptor to link to my Role table.
I don't know what to put as foreignKeyField and foreignKeyValue nor how to link the secondaty table to my field. All the things that I've tried lead me to show an empty grid.
Can you help me? The documentation is not very explainatory.
2) I've defined the same grid with a excel type filter.
If I filter by name, everything looks allright:

But if I filter by the empty column "Phone #" I got this:

What is happening?
Thanks in advance
Toni

1 Reply

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team October 22, 2018 12:38 PM UTC

Hi Toni, 

Thanks for contacting Syncfusion Support. 

Query#1:- I don't know what to put as foreignKeyField and foreignKeyValue nor how to link the secondaty table to my field. All the things that I've tried lead me to show an empty Grid. 
 
We can reproduce your reported problem at our end while using webMethodAdaptor of DataManager to Grid. In your code example you have used both webMethod Adaptor and ForeignKey Adaptor which is the cause of the problem. The documentation you have referred explains about  ForeignKey Adaptor. We shouldn’t use ForeignKey Adaptor in combination with ForeignKey Adaptor. To overcome this problem, on using webmethod Adaptor we suggest you to use ForeignKeyField and ForeignKeyValue property of Columns as like given code example and documentation Link below:- 

<ej:Grid ID="FlatGrid" runat="server" AllowPaging="true" AllowGrouping="true" AllowFiltering="true" AllowSorting="true" AllowSearching="true"> 
           <DataManager URL="/Default.aspx/DataSource"  Adaptor="WebMethodAdaptor" /> 
            <FilterSettings FilterType="Excel" />  
               <Columns> 
                <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="True" TextAlign="Right" Width="75" /> 
                <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="80" /> 
                <ej:Column Field="EmployeeID" HeaderText="Employee Name" ForeignKeyField="EmployeeID" ForeignKeyValue ="FirstName"  TextAlign ="Right" Width="80" /> 
                  .  .    . 
            </Columns> 
        </ej:Grid> 
    </div> 
 
 
[WebMethod] 
 
         protected void Page_Load(object sender, EventArgs e) 
 
        { 
            this.FlatGrid.Columns[2].DataSource = Employee; 
            this.FlatGrid.DataBind(); 
            BindDataSource(); 
            BindData(); 
 
        } 
 
         
        public class Employees 
        { 
            public int EmployeeID { get; set; } 
            public string FirstName { get; set; } 
            public string Country { get; set; } 
            public int ID { get; set; } 
 
 
        } 
        
         
        public class Orders 
        { 
            public long OrderID { get; set; } 
            public string CustomerID { get; set; } 
            public int EmployeeID { get; set; } 
 
 
        } 
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
        public static object DataSource(Syncfusion.JavaScript.DataManager value) 
        { 
 
            IEnumerable GridData = order; 
            IEnumerable empData = Employee; 
            DataOperations ds = new DataOperations(); 
            if (value.Where != null && value.Where.Count > 0) //Filtering 
            { 
                GridData = ds.PerformWhereFilter(GridData, value.Where, value.Where[0].Operator); 
            } 
 
            var count = GridData.Cast<Orders>().Count(); 
 
            
            if (value.Skip > 0) 
                GridData = ds.PerformSkip(GridData, value.Skip); 
           
            if(value.Take > 0) 
               GridData = ds.PerformTake(GridData, value.Take); 
 
            return new { result = GridData, count = count }; 
        } 


 
 
Query#2:- I've defined the same grid with a excel type filter. But if I filter by the empty column "Phone #" I got this: 

The reported problem occurs when we bind empty dataSource for the Grid. When you bind the empty data source, Grid cannot find the actual data type of a column. In this case, you have to set the Type property of the column to perform the filtering operation.   


Please refer to the documentation link:- https://help.syncfusion.com/aspnet/grid/columns#type 
 
Please get back to us if you need any further assistance.  

Regards,  

Farveen sulthana T  


Loader.
Up arrow icon