Discussions
Categories
- 385.5K All Categories
- 5K Data
- 2.5K Big Data Appliance
- 2.5K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
oj-table refresh data

I use the oj-table on my page. The first time I load data for the table, I got 68 data from the server, and all the data can be displayed in the table.
After that, whatever I refresh the table data, it only display 34 lines in the table. Actually, there are more than 34 data.
But if you click the table header to sort the data, all of data will be displayed.
The oj version I used is v8.1.0
codes:
HTML
<oj-table id='departmentTable' aria-label=''
data='[[departmentDataProvider]]'
columns='{{departmentColumnArray}}'
selection-mode='{"row": "multiple"}'
style='width: 100%;'>
</oj-table>
<script type="text/html" id="departmentTable_department_name">
<td>
<span data-bind="text: $context.row.departmentName"></span>
</td>
</script>
<script type="text/html" id="departmentTable_department_manager">
<td>
<span data-bind="text: $context.row.departmentManager"></span>
</td>
</script>
JS
var self = this;
self.departmentColumnArray = [
{ headerText: 'Department Name', field: 'departmentName', renderer: oj.KnockoutTemplateUtils.getRenderer('departmentTable_department_name', true)},
{ headerText: 'Department Manager', field: 'departmentManager', renderer: oj.KnockoutTemplateUtils.getRenderer('departmentTable_department_manager', true)}
];
self.departmentData = ko.observableArray();
self.departmentDataProvider = new oj.ArrayDataProvider(self.departmentData, { keyAttributes: 'departmentId' });
self.data = new Array();
self.firstLoadData = function(){
//all the data can be displayed in the table
for(let i = 1; i <= 68; i++){
self.data.push({
'departmentId': i,
'departmentName': 'Department' + i,
'departmentManager': 'Manager' + i
});
}
self.departmentData(self.data);
};
self.num = -1;
self.getDataFromServer = function(){
var responseData = {
'status': 'error'
};
if(data.length + self.num <= 0){
return responseData;
}
responseData.status = 'success';
responseData.dataArr = self.data.slice(0, self.num--);
return responseData;
};
self.refreshDepartment = function(){
//if the amount of data >= 34,then only the first 34 lines display in the table.
self.departmentData.removeAll();
var responseData = self.getDataFromServer();
if(responseData.status == 'success'){
self.departmentData(responseData.dataArr);
}
};
Answers
-
John JB Brock-Oracle Senior Manager of Product Management, Oracle JET Seattle, WA, USAPosts: 2,911 Employee
The only thing I can think of to look at first would be if the keyAttributes value that you have set in your DataProvider is truly a uniqueId and you do not have duplicates in your dataset.
-
I have faced similar issue and the suggestion solved. I was using a column 'code' as id Attribute where in reality it is not unique between rows. So changed the idAttribute to 'id' instead of 'code'.(Note: 'id' is not a column. It just took its own ref). Then the data got auto refreshed as soon as the observable is changed.
----------------------------------------------------------------------------------------- JS code -----------------------------------------
self.testArr = ko.observableArray();
//self.testDS = new PagingDataProviderView(new ArrayDataProvider(self.testArr, { idAttribute: 'code' })); ===> REFRESH NOT WORKING
self.testDS = new PagingDataProviderView(new ArrayDataProvider(self.testArr, { idAttribute: 'id' })); //// REFRESH WORKING
self.testCols = ko.observable();
self.testCols([{
"headerText": "code",
"field": "code",
"id": "test_code"
},
{
"headerText": "amount",
"field": "amnt",
"id": "test_amnt"
}
]);
var dir1 ={ "code":"c1","amnt":100 };
self.testArr.push(dir1);
var dir2 ={ "code":"c1","amnt":20 };
self.testArr.push(dir2);
-----------table------------------------------------------------------------------------------------------------------------------
<oj-table aria-label="Test Table" id="test-details-table" data='[[testDS]]'
selection-mode='{"row": "single", "column": "multiple"}' columns='[[testCols]]'
columns-default='{"sortable": "disabled" }' row-renderer="[[testTableRowRenderer]]"
scroll-policy='loadMoreOnScroll' class="width100">
<oj-paging-control class="lastTab" id="test_paging" data='[[testDS]]'
page-options='{"type":"Number"}' page-size='5' slot='bottom'>
</oj-paging-control>
</oj-table>
------------------------------------------------------------------------------------------------------------------------------------
-
Check by changing keyAttributes --> from 'departmentId' ti 'id'
-
For completeness sake, let me make the following remarks:
- idAttribute is deprecated and you should use keyAttributes instead
- Specifying a non-existent field name as 1066874 recommends is not offically supported. Instead, you can simply not specify any keyAttributes, in which case the DataProvider will default to using the array index (which is guaranteed to be unique of course).
Source: https://www.oracle.com/webfolder/technetwork/jet/jsdocs/ArrayDataProvider.html#constructor-section