开发者

jQuery Grid Binding in ASP .NET MVC is so slow [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

I am using the Infragistics jQuery grid in my ASP .NET MVC application. My datasource is an ADO .NET Entity model referencing an SQL database. Here is the code from my controller to set up the grid and provide the datasource for it to pull from:

public ActionResult Index()
{
   var model = new GridModel();
   model.DataSourceUrl = Url.Action("GetInstrumentListData");
   this.InitializeGridOptions(model);
   return View(model);
}

public JsonResult GetInstrumentListData()
{
   var model = new GridModel();
   this.InitializeGridOptions(model);
   model.DataSource = _db.InstrumentLists.OrderBy(x => x.Tag).AsQueryable<InstrumentList>();
   return model.GetData();
}

private void InitializeGridOptions(GridModel model)
{
   Code to create columns...

   model.DefaultColumnWidth = "100px";
   model.Width = "100%";
   model.Height = "700px";

   model.Features.Add(new GridFiltering());

   var sort = new GridSorting();
   sort.Mode = SortingMode.Multiple;
   model.Features.Add(sort);

   var paging = new GridPaging();
   paging.PageSize = 30;
   model.Features.Add(paging);

   var selection = new GridSelection();
   selection.Mode = Selecti开发者_如何学JAVAonMode.Row;
   selection.MultipleSelection = true;
   model.Features.Add(selection);
}

The grid was taking ages to display (25-40 secs) so I did some investigating and it's the model.GetData() call in GetInstrumentListData() that is taking up all the time. According to Intellisense, this function first performs data binding and generates the JsonResult object.

I thought that maybe since I was attempting to display a total of 1000 records (even though pagination is enabled and only displaying 30 each view) that maybe it was taking a while to convert those records into JSON, so I reduced the amount of records to 10 (from 1.2mb of JSON data to 12.5kb). There was no difference in time.

Here is the request tracing from Firebug.

jQuery Grid Binding in ASP .NET MVC is so slow [closed]

Any ideas on what is happening?

EDIT: @allentranks' answer and @AlastairPitts comment made me realise that it is in fact the source I am getting my data from. The source isn't a table but a view, which was created by my DBA from a whole bunch of crazy joins. Turns out that it takes 13+ secs to run the query, so its no wonder its taking so long to load. Thanks for your help.


I am not sure why your InstrumentLists need to be ordered twice in your query.

_db.InstrumentLists.OrderBy(x => x.Tag).AsQueryable<InstrumentList>().OrderBy(x => x.Tag);

this should work:

_db.InstrumentLists.OrderBy(x => x.Tag).ToList();

And, you maybe need to create an index on the Tag column to execute the query more quickly.


There is something wrong with data that you are returning from controller (amount of data is too much. 12.5kb for 10 records!). you should inspect json data returned from the server in firebug. Make sure that you are only receiving data that is required and specific to the grid. i would suggest making a custom view model for the grid.

As a side note i would like to share that for a grid with 50 records per page and 11 columns the json data i receive is 1.9 kb and its 967 bytes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜