This is a migrated thread and some comments may be shown as answers.

DataSourceResult Help

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 24 Feb 2016, 04:59 PM

Hello, 

I was wondering if there was any way to add conditions to a datasourcereulst like "Where" and"Union"?  Here is my controller code.

public ActionResult tbl_vessels_Read([DataSourceRequest]DataSourceRequest request, decimal[] param_bhp, decimal[] param_deck)
      {
          IEnumerable<tbl_vessels> tbl_vessels = db.tbl_vessels;
          DataSourceResult result = tbl_vessels.ToDataSourceResult(request,
              
              c => new tbl_vessels
               
          {
              vessel_idx = c.vessel_idx,
              vessel_name = c.vessel_name,               
              spotlist_dp = c.spotlist_dp,
              spotlist_bhp = c.spotlist_bhp,
              spotlist_deck = c.spotlist_deck,
              spotlist_bp = c.spotlist_bp,
              spotlist_oilrec = c.spotlist_oilrec,
              spotlist_fifi = c.spotlist_fifi,
              spotlist_rov = c.spotlist_rov,
              charterer_info = c.charterer_info
          });
          JsonResult data;
 
          if (param_bhp == null && param_deck == null)
          {
              data = Json(tbl_vessels);
          }
          else
          {
              data = Json(tbl_vessels.Where(
                  w => w.spotlist_bhp > param_bhp[0] &&
                       w.spotlist_bhp < param_bhp[1] &&
                       w.spotlist_deck > param_deck[0] &&
                       w.spotlist_deck < param_deck[1]
                  ).ToDataSourceResult(request));
          }
          return data;
      }

As you can see I also have sliders which means that my dataresults need to be enumerable, IQueryable isn't allowed on array.  So how can I add some conditions to the DataSourseResult like "Where" etc??

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 29 Feb 2016, 07:40 AM

Hello Allan,

The purpose of ToDataSourceResult is to apply the operations described in the DataSource descriptors. The equivalent of Where in this context is the Filter operation, therefore if you want to apply restrictions which to be processed by the ToDataSourceResult you should described them as a filter descriptors and merge them with those from the DataSourceRequest if such exist.  

If you want to filter the collection externally, you should apply the Where clause before passing the data to the ToDataSourceResult. This will ensure that the results returned by the ToDataSourceResult are correct, for example that the correct number of records is returned to the client.

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Allan
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or