0

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 = SelectionMode.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.
Request tracing

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.

1
  • How many rows are there in the InstrumentList table? Do you have an index on the Tag column? The query suggests that you're pulling all the rows from that table Commented Aug 24, 2011 at 3:15

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Oops, OrderBy twice was a copy and paste error, it actually is only in my code once, which I've now fixed in the question post.
And its not the query the query that is taking the time, it is the line following it - return model.GetData()
@link664: It's using deferred loading, so that query isn't actually being executed until you call .GetData(). To force loading before .GetData() call .ToList() as @allentranks mentions.
See edit - it was the datasource. Thanks for leading me to the answer.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.