Use any row data passed from server in etemplate load call to avoid an extra call to get_rows

This commit is contained in:
Nathan Gray 2014-01-09 11:25:08 +00:00
parent a9c800229c
commit 49ef2c538a
3 changed files with 48 additions and 1 deletions

View File

@ -96,7 +96,7 @@ class etemplate_widget_nextmatch extends etemplate_widget
/**
* Number of rows to send initially
*/
const INITIAL_ROWS = 25;
const INITIAL_ROWS = 50;
/**
* Set up what we know on the server side.

View File

@ -184,6 +184,34 @@ var et2_dataview_controller = Class.extend({
}
},
/**
* Load initial data
*
* @param {string} uid_key Name of the unique row identifier field
* @param {Object} data Key / Value mapping of initial data.
*/
loadInitialData: function (uid_prefix, uid_key, data) {
var idx = 0;
for(var key in data)
{
// Skip any extra keys
if(typeof data[key] != "object" || data[key] == null || typeof data[key][uid_key] == "undefined") continue;
// Add to row / uid map
var entry = this._getIndexEntry(idx++);
entry.uid = data[key][uid_key];
if(entry.uid.indexOf(uid_prefix) < 0)
{
entry.uid = uid_prefix + "::" + entry.uid;
}
// Add to data cache so grid will find it
egw.dataStoreUID(entry.uid, data[key])
// Don't try to insert the rows, grid will do that automatically
}
},
/**
* Returns the depth of the controller instance.
*/

View File

@ -889,6 +889,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput],
null,
this.options.actions
);
// Need to trigger empty row the first time
if(total == 0) this.controller._emptyRow();
@ -910,6 +911,24 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput],
this.options.settings.total : 0;
// This triggers an invalidate, which updates the grid
this.dataview.grid.setTotalCount(total);
// Insert any data sent from server, so invalidate finds data already
if(this.options.settings.rows)
{
var prefix = this.options.settings.dataStorePrefix;
if(!prefix)
{
prefix = this.options.settings.get_rows.split('.');
prefix = prefix[0];
}
this.controller.loadInitialData(
prefix,
this.options.settings.row_id,
this.options.settings.rows
);
// Remove, to prevent duplication
delete this.options.settings.rows;
}
},
_parseGrid: function(_grid) {