I have an observable array ListingData
which I am using to bind data in a HTML table using knockout like this:
<tbody data-bind="foreach: ListingData">
<tr>
<!-- ko foreach: $parent.OrderedColumns -->
<td>
<span data-bind="text: $parent[$data]"></span>
</td>
<!-- /ko -->
</tr>
</tbody>
OrderedColumns
is a simple array containing the column names which I am using to bind the grid data dynamically. Since the user can configure the number rows and columns which will be displayed in the grid, I am using the above syntax.
The user can configure upto 500
rows and 50
columns maximum. I am getting the 50 x 500 data in a single ajax request and storing it into the ListingData
observable array. The problem I am facing is that when I set the value for ListingData
observable array, KO will try to generate the markup of all 50 columns and 500 rows given in the foreach
binding at once which is causing the browser to hang and it gives the Stop script
/ Continue script
message. I tested with 50
columns and 500
rows, it is taking about 6-7 secs to bind the data and during this period the browser is getting hanged.
My question is, is there anyway to generate markup as the user scrolls through the tbody
of html table using knockout? For example in my request I will get all 50
columns and 500
rows and store it into an observable array and on page load, only 10
or 20
records will be visible to the user. As the user scrolls through the html table, we need to generate the markup of remaining records using the data already present in the observable array, rather than making an ajax call to get the remaining records each time the user scrolls down. After scrolling through all 500
records, if the user clicks on next page, this time we will send an ajax request get the next 500 records and show only 10
or 20
records and generate markup as user scrolls down in the 2nd
page.
Is there any way to achieve this in Knockout like using knockout templates
or on demand loading
etc?