Posted by Randall Price
on 03.11.2006 20:53
Has anyone been able to get the LiveGrid to work (well) with ASP.NET 
yet?

I have been trying (using LiveGrid Plus from the 
http://dowdybrown.com/dbprod/ web site) and have had only moderate 
success.  If I use the pre-filled grid method it seems to work OK, but I 
really want to have a data-driven grid that gets populated from a 
backend database (in my case I am using MySQL).

Here are some specs for my application requirements:

1.  A dynamic grid that will display the number of rows to fill up the 
available space -- so I set the visibleRows parameter to -1 as 
suggested.  I am populating the grid from MySQL using an ASP.NET Generic 
Handler page (.ashx) and I don't know the number of records that will be 
returned beforehand.  So I am not sure what value to use for the 
totalRows parameter.  If I put in a number larger than the number of 
records returned it seems that the LiveGrid shows the extra rows as 
blank and allows me to scroll the data off the top of the grid.  An 
example is a recordset returns 61 rows but because of the default value 
of bufferExtend (100) the bookmark shows "Listing records xx of 161" 
when it should say "Listing records xx of 61".  I have a workaround for 
this by setting the totalRows to 1 and setting bufferExtend to 0.

2.  The ability for the grid to resize as the browser resizes (i.e., the 
number of visible rows should be able to increase / decrease as the 
browser is resized).  For example, in 1024x768 resolution, I can display 
about 30 rows.  If I resize the browser to 800x600 I can display about 
20 rows, but instead of the LiveGrid resizing automatically, I get a 
horizontal scrollbar on the browser window.  If I refresh the page, the 
LiveGrid resizes properly and displays the 20 rows.  So I suspect that I 
can get this to work by refreshing the LiveGrid in a resize event using 
JavaScript -- have not tried this yet with the LiveGrid but I have done 
this in other ASP.NET apps using the ASP.NET GridView control.

3.  The ability to specify a sort expression instead of just having the 
grid sort based on the content of the cells (i.e., I have a column of IP 
Addresses and I want to sort them based on the numeric value as returned 
from the MySQL ATON() function, which returns the IP Address converted 
to a number).

Here are some questions and observations:

1.  The sort does not work -- there is no sort parameters appended to 
the QueryString being sent to my data request handler.  I am using 
custom column specs for all columns.  Do I have to specify the canSort 
option for each column?

2.  The resizing of the whole grid is kind of flaky -- when I resize the 
browser window using the mouse, the grid does not resize properly.  If I 
drag the right border of the browser window back and forth, the grid 
incrementally gets bigger and somethimes smaller but is not very 
consistent.

3.  What is the proper way to code a data request handler?  Do I need to 
specify a query that retrieves ALL the records I want and just let 
LiveGrid handle retrieving just the records it needs for display (and 
buffering)?  Or do I need to handle paging by specifying an Index and 
PageSize parameters to my query?

All in all, LiveGrid is an excellent product and I look forward to 
incorporating it into my applications.  However, there are some issues 
that need to be worked out and improved it this is truly going to be 
able to replace the built-in GridView control supplied with ASP.NET in 
my applications.

Thanks,

Randall Price
Posted by Ken Gregg
on 03.11.2006 22:13
Randal,

I'll cover the things I can from memory. I just wrote a blog entry on
some of this this morning so it is still fresh.
(http://kens.sandbox.rwre.com/archives/9)

Hopefully this will get you going.

1. Fill available space. -1 in visible rows is right. Set prefetchBuffer
to true and number of rows to 1. In the xml that you return from your
data handler return rowcount tags like this:

<rowcount>61</rowcount>

This is the total number of rows and goes inside of the <response> tags.
bufferExtend is not used if the rowcount is included in the returned
data.

2. When I use the -1 for autosizing of the grid, it resizes fine when I
resize the browser window.

3. LiveGrid passes the sort parameters differently than LiveGrid 1.1.
Plus passes  sn= where n is the column to sort on. I think the value is
the direction (verify that). s0 would be the first column, s1 the second
one, ... I don't care for this as it takes a lot more processing to
figure out the sort column but I live with it. Filters are passed the
same way with f0, f1, ... set to <, >, =, like, and the value. You can 
filter on
multiple columns but can sort only one at a time.

I use an array in my code to map the passed in column to the order by
clause to use. Unless you specify it in your column spec sort ability
defaults to whatever canSortDefault is set to.

As for the data handler if you are using MySQL use the offset and
pagesize in a limit clause. Here is what I use for my queries. It's php
but you should be able to translate easily.

  $limit = ' LIMIT ' . $offset . ',' . $page_size . ';';

  $sql = 'SELECT SQL_CALC_FOUND_ROWS ' . $sql_fields . ' FROM ' . $table
. ' WHERE ' . $where . $sort . $limit;
  $result = $db->query($sql);
  if ($db->error())
    die($db->error() . '<br>' . $sql);

  $count_sql = 'SELECT FOUND_ROWS();';
  $result2 = $db->query($count_sql);
  $tmp = $db->fetch_assoc($result2);
  $nrows = $tmp['FOUND_ROWS()'];

$nrows ends up with the value I put in <rowcount>.

Hope this helps

Ken
Posted by Alex Botez
on 20.10.2008 10:02
You can check out an adaptation of the JS LiveGrid on
http://www.sharppieces.com/free-aspnet-controls/LiveGrid.aspx .