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
close icon

Need Full Featured Grid Example

The data grid appears capable of a lot by looking at other examples, but the very simple example on the Aurelia section of the site really doesn't put together a fully featured example.  Here's what I'm try to do but having trouble finding examples that work:

- have the grid call a REST Api for data with paging, sort, and filter arguments.
- have the grid call the REST Api cross-domain.
- have the grid call the REST Api including parameters from the page.

Below is an attempt I made using various documentation references, but it doesn't work.  I'll include it as an example of what I want to accomplish.

The site is hosted at http://localhost:58000.

In page.ts:
export class page {
    public searchText;
    public searchResults;
    public page =0;

    public submit() {
      this.searchResults = new ej.DataManager({
              url: 'http://localhost:58700/api/values/find',
              crossDomain: true,
              adaptor: new ej.UrlAdaptor()
          })
          .executeQuery(new ej.Query().addParams("searchText", this.searchText));
      return true;
      }
}

In page.html:
          <ej-grid e-data-source.bind="searchResults" e-page-settings.bind="page" e-allow-paging=true>
              <ej-column e-field="id"></ej-column>
              <ej-column e-field="firstName"></ej-column>
              <ej-column e-field="lastName"></ej-column>
          </ej-grid>

The first problem is this error, which seems like the crossDomain=true argument is ignored:

"XMLHttpRequest cannot load http://localhost:58700/api/values/find. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:58000' is therefore not allowed access."

Help getting this to work is appreciated.



3 Replies

AS Alan Sangeeth S Syncfusion Team January 27, 2017 11:11 AM UTC

Hi Steve, 

Thanks for using Syncfusion products. 

We suspect that you have not configured your service to accept cross-origin requests which may be the cause of the issue. Please add the following code in your service web.config file. 
<system.webServer> 
    <httpProtocol> 
     <customHeaders> 
         <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" /> 
         <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,PUT,DELETE" /> 
     <add name="Access-Control-Allow-Origin" value="*" /> 
     </customHeaders> 
   </httpProtocol> 
 

Please refer the following link for further reference. 

Also we suggest you to use “query” property of Grid to send extra parameters to server-side. Please refer the following code example. 
<ej-grid id="Grid" e-data-source.two-way="gridData" e-allow-paging=true e-query.bind="searchQuery"> 
 
</ej-grid> 
 
 
export class Grid { 
 
this.searchQuery = new ej.Query().addParams("searchText", "test") 
} 


We have also created an Aurelia sample that can be downloadable from below link. 


Regards,
Alan Sangeeth S 



SK Steve Kinyon January 27, 2017 05:43 PM UTC

Thanks for the sample, I'll take a look and see how it goes.  I hadn't previously noticed the e-query tag, so that might help.

On the cross domain call, I already have an Aurelia HttpClient calling the API and returning data without issue, so I know the API is working in general.  But the specific call might be having problems.

What is the signature for receiving call?  I'm using ASP.NET Core Api (so that web.config isn't valid for me anyways).  I'd like to handle the call using arguments rather than an adapter if that is possible.  The data store is MongoDB and the adapters seem to be focused on an IQueryable data store like EntityFramework.

Lastly, is it possible to use setup the grid to use another data access tool, such as HttpClient instead of egDataManager & ejQuery?  If so, do you have an example that can work with paging, sort, and filter arguments?


TS Thavasianand Sankaranarayanan Syncfusion Team January 30, 2017 01:34 PM UTC

Hi Steve, 
 
We have analyzed your query and we suspect that you have perform the paging, sorting, filtering actions in the server side using the HttpClient.  
 
In Url adaptor sample the DataManager parameter contains all the required parameters for  performing server side operations such as paging, sorting, searching and filtering. From the obtained DataManager class parameter values you can perform the server side operation using HttpClient instead of Dataoperations class.  
 
 
Refer the screenshot. 

 


For more information, refer the KB for the server side operations 
 
 
Regards, 
Thavasianand S. 


Loader.
Live Chat Icon For mobile
Up arrow icon