我有一个sap.m.表,其中growing(true)
和growingThreshold
设置为5和MultiSelect
模式。说,无论何时,我的JSON模型中的记录数都超过了5(例如20)。因此,它将始终执行延迟加载。
我有一个按钮,需要选择模型中的所有元素,即20个项目。因此,在按钮的单击处理程序上,我说:-table.selectAll()
。
现在,由于UI(和DOM)中仅显示5个项目,因此UI5库仅选择显示的元素。
console.log('How many items selected ?', oTable.getSelectedContexts(true).length ) // says 5. But it needs to be 20.
问题是-如何选择所有项目而不将其加载到UI中?显示所有元素以仅选择它们对我来说没有意义。
现在
代码:
<ToggleButton text='Select All' press='onSelectAll'/>
<Button text='Submit' press='onSubmit' />
<Table noDataText="No Data" id="table0" items="{/}" mode='MultiSelect' growing='true' growingThreshold='5'>
<items>
<ColumnListItem type="Active">
<cells>
<Text text="{id}"/>
<Text text="{name}"/>
</cells>
</ColumnListItem>
</items>
<columns>
<Column id="column0">
<header>
<Label text="ID" id="label0"/>
</header>
</Column>
<Column id="column1">
<header>
<Label text="NAME" id="label1"/>
</header>
</Column>
</columns>
</Table>
控制器:
onInit: function () {
var aData = [];
for(var i =0;i< 20; i++) {
var element = {
id : 'I00' + i,
name: 'Clone-' + i
};
aData.push(element);
}
var oModel = new sap.ui.model.json.JSONModel(aData);
this.getView().setModel(oModel);
},
onSelectAll: function (oEvent) {
var oSource = oEvent.getSource();
var oTable = this.byId('table0');
if (oSource.getPressed()) {
oTable.selectAll();
} else {
oTable.removeSelections(true);
}
},
onSubmit: function() {
var oTable = this.byId('table0');
console.log('How many items selected ?', oTable.getSelectedContexts(true).length );
}