
I have a angular ui-grid as below in HTML
<div id="grid1" ui-grid="gridOptions" ui-grid-edit class="grid"></div>
In the JS, I am getting data from pouchdb and storing the result to an object
function find_users_by_name(name) {
if( !name.id ) { // This is not a callback from 'db.change'
myId = name;
oldId = name;
}
else // This is called from db.change
myId = oldId;
db.query('idx/bypin', {
key: myId,
include_docs: true
}).then(function(result) {
$scope.todo = result.rows;
}).catch(function(err) {
// handle errors
alert('not found');
});
$scope.gridOptions = { enableSorting: true, enableColumnResizing:true };
$scope.gridOptions.data = $scope.todo;
$scope.gridOptions.columnDefs = [
{name: 'Address1',field: "Address1"},
{name: 'Address2',field: "Address2"}
];
}
However, the grid is created with no. of rows as in result, and just shows the column headers, but I don't find in any data.
What is it I am doing wrong here?
TIA!
Query to the in browser database is asynchronous. As you can see you are using promises.
And your assigning of todo to grid data is immediately after the declaration of the call to the in browser database.
Please move this assignment inside the then function or declare another then and do your next steps there.
Good luck