demos/tableview-preload/tableview.go
func (d *dbCache) preload(firstRow, rowCount int) {
	if firstRow == d.firstRow && rowCount == d.rowCount {
		// fast path: view area is the same, return immediately
		return
	}

	// slow path: refill cache
	fNames := []string{"Jack", "Alisa", "Richard", "Paul", "Nicole", "Steven", "Jane"}
	lNames := []string{"Smith", "Catcher", "Stone", "White", "Black"}
	posts := []string{"Engineer", "Manager", "Janitor", "Driver"}
	deps := []string{"IT", "Financial", "Support"}
	salary := []int{40000, 38000, 41000, 32000}

	d.data = make([][]string, rowCount, rowCount)
	for i := 0; i < rowCount; i++ {
		absIndex := firstRow + i
		d.data[i] = make([]string, columnInTable, columnInTable)
		d.data[i][0] = fNames[absIndex%len(fNames)]
		d.data[i][1] = lNames[absIndex%len(lNames)]
		d.data[i][2] = fmt.Sprintf("%08d", 100+absIndex)
		d.data[i][3] = posts[absIndex%len(posts)]
		d.data[i][4] = deps[absIndex%len(deps)]
		d.data[i][5] = fmt.Sprintf("%d k/year", salary[absIndex%len(salary)]/1000)
	}

	// do not forget to save the last values
	d.firstRow = firstRow
	d.rowCount = rowCount
}
func (d *dbCache) preload(firstRow, rowCount int) {
	if firstRow == d.firstRow && rowCount == d.rowCount {
		// fast path: view area is the same, return immediately
		return
	}

	// slow path: refill cache
	fNames := []string{"Jack", "Alisa", "Richard", "Paul", "Nicole", "Steven", "Jane"}
	lNames := []string{"Smith", "Catcher", "Stone", "White", "Black"}
	posts := []string{"Engineer", "Manager", "Janitor", "Driver"}
	deps := []string{"IT", "Financial", "Support"}
	salary := []int{40000, 38000, 41000, 32000}

	d.data = make([][]string, rowCount, rowCount)
	for i := 0; i < rowCount; i++ {
		absIndex := firstRow + i
		d.data[i] = make([]string, columnInTable, columnInTable)
		d.data[i][0] = fNames[absIndex%len(fNames)]
		d.data[i][1] = lNames[absIndex%len(lNames)]
		d.data[i][2] = fmt.Sprintf("%08d", 100+absIndex)
		d.data[i][3] = posts[absIndex%len(posts)]
		d.data[i][4] = deps[absIndex%len(deps)]
		d.data[i][5] = fmt.Sprintf("%d k/year", salary[absIndex%len(salary)]/1000)
	}

	// do not forget to save the last values
	d.firstRow = firstRow
	d.rowCount = rowCount
}
// cache data from a new row span
// It imitates a random data by selecting values from predefined arrays. Sizes
// of all arrays should be different to make TableView data look more random