update FluTableView

This commit is contained in:
朱子楚\zhuzi 2024-03-01 23:24:03 +08:00
parent 6a73ac97df
commit 72b777dec3
6 changed files with 428 additions and 135 deletions

View File

@ -14,6 +14,16 @@ FluContentPage{
property var dataSource : [] property var dataSource : []
property int sortType: 0 property int sortType: 0
property bool seletedAll: true property bool seletedAll: true
property string nameKeyword: ""
onNameKeywordChanged: {
table_view.filter(function(item){
if(item.name.includes(nameKeyword)){
return true
}
return false
})
}
Component.onCompleted: { Component.onCompleted: {
loadData(1,1000) loadData(1,1000)
@ -34,23 +44,25 @@ FluContentPage{
if(sortType === 0){ if(sortType === 0){
table_view.sort() table_view.sort()
}else if(sortType === 1){ }else if(sortType === 1){
table_view.sort((l, r) =>{ table_view.sort(
var lage = Number(l.age) (l, r) =>{
var rage = Number(r.age) var lage = Number(l.age)
if(lage === rage){ var rage = Number(r.age)
return l._key>r._key if(lage === rage){
} return l._key>r._key
return lage>rage }
}); return lage>rage
});
}else if(sortType === 2){ }else if(sortType === 2){
table_view.sort((l, r) => { table_view.sort(
var lage = Number(l.age) (l, r) => {
var rage = Number(r.age) var lage = Number(l.age)
if(lage === rage){ var rage = Number(r.age)
return l._key>r._key if(lage === rage){
} return l._key>r._key
return lage<rage }
}); return lage<rage
});
} }
} }
@ -90,6 +102,57 @@ FluContentPage{
} }
} }
FluMenu{
id:pop_filter
width: 200
height: 89
contentItem: Item{
onVisibleChanged: {
if(visible){
name_filter_text.text = root.nameKeyword
name_filter_text.cursorPosition = name_filter_text.text.length
name_filter_text.forceActiveFocus()
}
}
FluTextBox{
id:name_filter_text
anchors{
left: parent.left
right: parent.right
top: parent.top
leftMargin: 10
rightMargin: 10
topMargin: 10
}
iconSource: FluentIcons.Search
}
FluButton{
text:"搜索"
anchors{
bottom: parent.bottom
right: parent.right
bottomMargin: 10
rightMargin: 10
}
onClicked: {
root.nameKeyword = name_filter_text.text
pop_filter.close()
}
}
}
function showPopup(){
table_view.closeEditor()
pop_filter.popup()
}
}
Component{ Component{
id:com_checbox id:com_checbox
Item{ Item{
@ -107,6 +170,38 @@ FluContentPage{
} }
} }
Component{
id:com_column_filter_name
Item{
FluText{
text:"姓名"
anchors.centerIn: parent
}
FluIconButton{
width: 20
height: 20
iconSize: 12
verticalPadding:0
horizontalPadding:0
iconSource: FluentIcons.Filter
iconColor: {
if("" !== root.nameKeyword){
return FluTheme.primaryColor
}
return FluTheme.dark ? Qt.rgba(1,1,1,1) : Qt.rgba(0,0,0,1)
}
anchors{
right: parent.right
rightMargin: 3
verticalCenter: parent.verticalCenter
}
onClicked: {
pop_filter.showPopup()
}
}
}
}
Component{ Component{
id:com_action id:com_action
Item{ Item{
@ -324,10 +419,20 @@ FluContentPage{
text:"删除选中" text:"删除选中"
onClicked: { onClicked: {
var data = [] var data = []
for(var i =0;i< table_view.rows ;i++){ var rows = []
var item = table_view.getRow(i) for (var i = 0; i < table_view.rows; i++) {
if(false === item.checkbox.options.checked){ var item = table_view.getRow(i);
data.push(item) rows.push(item)
if (!item.checkbox.options.checked) {
data.push(item);
}
}
var sourceModel = table_view.sourceModel;
for (i = 0; i < sourceModel.rowCount; i++) {
var sourceItem = sourceModel.getRow(i);
const foundItem = rows.find(item=> item._key === sourceItem._key)
if (!foundItem) {
data.push(sourceItem);
} }
} }
table_view.dataSource = data table_view.dataSource = data
@ -370,7 +475,7 @@ FluContentPage{
width:100 width:100
}, },
{ {
title: '姓名', title: table_view.customItem(com_column_filter_name,{title:'姓名'}),
dataIndex: 'name', dataIndex: 'name',
readOnly:true readOnly:true
}, },

View File

@ -14,6 +14,16 @@ FluContentPage{
property var dataSource : [] property var dataSource : []
property int sortType: 0 property int sortType: 0
property bool seletedAll: true property bool seletedAll: true
property string nameKeyword: ""
onNameKeywordChanged: {
table_view.filter(function(item){
if(item.name.includes(nameKeyword)){
return true
}
return false
})
}
Component.onCompleted: { Component.onCompleted: {
loadData(1,1000) loadData(1,1000)
@ -34,23 +44,25 @@ FluContentPage{
if(sortType === 0){ if(sortType === 0){
table_view.sort() table_view.sort()
}else if(sortType === 1){ }else if(sortType === 1){
table_view.sort((l, r) =>{ table_view.sort(
var lage = Number(l.age) (l, r) =>{
var rage = Number(r.age) var lage = Number(l.age)
if(lage === rage){ var rage = Number(r.age)
return l._key>r._key if(lage === rage){
} return l._key>r._key
return lage>rage }
}); return lage>rage
});
}else if(sortType === 2){ }else if(sortType === 2){
table_view.sort((l, r) => { table_view.sort(
var lage = Number(l.age) (l, r) => {
var rage = Number(r.age) var lage = Number(l.age)
if(lage === rage){ var rage = Number(r.age)
return l._key>r._key if(lage === rage){
} return l._key>r._key
return lage<rage }
}); return lage<rage
});
} }
} }
@ -90,6 +102,57 @@ FluContentPage{
} }
} }
FluMenu{
id:pop_filter
width: 200
height: 89
contentItem: Item{
onVisibleChanged: {
if(visible){
name_filter_text.text = root.nameKeyword
name_filter_text.cursorPosition = name_filter_text.text.length
name_filter_text.forceActiveFocus()
}
}
FluTextBox{
id:name_filter_text
anchors{
left: parent.left
right: parent.right
top: parent.top
leftMargin: 10
rightMargin: 10
topMargin: 10
}
iconSource: FluentIcons.Search
}
FluButton{
text:"搜索"
anchors{
bottom: parent.bottom
right: parent.right
bottomMargin: 10
rightMargin: 10
}
onClicked: {
root.nameKeyword = name_filter_text.text
pop_filter.close()
}
}
}
function showPopup(){
table_view.closeEditor()
pop_filter.popup()
}
}
Component{ Component{
id:com_checbox id:com_checbox
Item{ Item{
@ -107,6 +170,38 @@ FluContentPage{
} }
} }
Component{
id:com_column_filter_name
Item{
FluText{
text:"姓名"
anchors.centerIn: parent
}
FluIconButton{
width: 20
height: 20
iconSize: 12
verticalPadding:0
horizontalPadding:0
iconSource: FluentIcons.Filter
iconColor: {
if("" !== root.nameKeyword){
return FluTheme.primaryColor
}
return FluTheme.dark ? Qt.rgba(1,1,1,1) : Qt.rgba(0,0,0,1)
}
anchors{
right: parent.right
rightMargin: 3
verticalCenter: parent.verticalCenter
}
onClicked: {
pop_filter.showPopup()
}
}
}
}
Component{ Component{
id:com_action id:com_action
Item{ Item{
@ -324,10 +419,20 @@ FluContentPage{
text:"删除选中" text:"删除选中"
onClicked: { onClicked: {
var data = [] var data = []
for(var i =0;i< table_view.rows ;i++){ var rows = []
var item = table_view.getRow(i) for (var i = 0; i < table_view.rows; i++) {
if(false === item.checkbox.options.checked){ var item = table_view.getRow(i);
data.push(item) rows.push(item)
if (!item.checkbox.options.checked) {
data.push(item);
}
}
var sourceModel = table_view.sourceModel;
for (i = 0; i < sourceModel.rowCount; i++) {
var sourceItem = sourceModel.getRow(i);
const foundItem = rows.find(item=> item._key === sourceItem._key)
if (!foundItem) {
data.push(sourceItem);
} }
} }
table_view.dataSource = data table_view.dataSource = data
@ -370,7 +475,7 @@ FluContentPage{
width:100 width:100
}, },
{ {
title: '姓名', title: table_view.customItem(com_column_filter_name,{title:'姓名'}),
dataIndex: 'name', dataIndex: 'name',
readOnly:true readOnly:true
}, },

View File

@ -8,12 +8,17 @@ FluTableSortProxyModel::FluTableSortProxyModel(QSortFilterProxyModel *parent)
_model = nullptr; _model = nullptr;
connect(this,&FluTableSortProxyModel::modelChanged,this,[=]{ connect(this,&FluTableSortProxyModel::modelChanged,this,[=]{
setSourceModel(this->model()); setSourceModel(this->model());
sort(0,Qt::AscendingOrder);
}); });
} }
bool FluTableSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const{ bool FluTableSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const{
return true; QJSValue filter = _filter;
if(filter.isUndefined()){
return true;
}
QJSValueList data;
data<<source_row;
return filter.call(data).toBool();
} }
bool FluTableSortProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const{ bool FluTableSortProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const{
@ -22,7 +27,7 @@ bool FluTableSortProxyModel::filterAcceptsColumn(int source_column, const QModel
bool FluTableSortProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const{ bool FluTableSortProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const{
QJSValue comparator = _comparator; QJSValue comparator = _comparator;
if(comparator.isNull()){ if(comparator.isUndefined()){
return true; return true;
} }
QJSValueList data; QJSValueList data;
@ -36,14 +41,24 @@ bool FluTableSortProxyModel::lessThan(const QModelIndex &source_left, const QMod
} }
} }
void FluTableSortProxyModel::setSortComparator(QJSValue comparator){ void FluTableSortProxyModel::setComparator(QJSValue comparator){
int column = 0;
if(comparator.isUndefined()){
column = -1;
}
this->_comparator = comparator; this->_comparator = comparator;
if(sortOrder()==Qt::AscendingOrder){ if(sortOrder()==Qt::AscendingOrder){
sort(0,Qt::DescendingOrder); sort(column,Qt::DescendingOrder);
}else{ }else{
sort(0,Qt::AscendingOrder); sort(column,Qt::AscendingOrder);
} }
} }
void FluTableSortProxyModel::setFilter(QJSValue filter){
this->_filter = filter;
invalidateFilter();
}
QVariant FluTableSortProxyModel::getRow(int rowIndex){ QVariant FluTableSortProxyModel::getRow(int rowIndex){
QVariant result; QVariant result;
QMetaObject::invokeMethod(_model, "getRow",Q_RETURN_ARG(QVariant, result),Q_ARG(int, mapToSource(index(rowIndex,0)).row())); QMetaObject::invokeMethod(_model, "getRow",Q_RETURN_ARG(QVariant, result),Q_ARG(int, mapToSource(index(rowIndex,0)).row()));

View File

@ -17,11 +17,13 @@ public:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const override; bool filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override; bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
Q_INVOKABLE void setSortComparator(QJSValue comparator);
Q_INVOKABLE QVariant getRow(int rowIndex); Q_INVOKABLE QVariant getRow(int rowIndex);
Q_INVOKABLE void setRow(int rowIndex,QVariant val); Q_INVOKABLE void setRow(int rowIndex,QVariant val);
Q_INVOKABLE void removeRow(int rowIndex,int rows); Q_INVOKABLE void removeRow(int rowIndex,int rows);
Q_INVOKABLE void setComparator(QJSValue comparator);
Q_INVOKABLE void setFilter(QJSValue filter);
private: private:
QJSValue _filter;
QJSValue _comparator; QJSValue _comparator;
}; };

View File

@ -12,6 +12,9 @@ Rectangle {
property alias columns: table_view.columns property alias columns: table_view.columns
property bool horizonalHeaderVisible: true property bool horizonalHeaderVisible: true
property bool verticalHeaderVisible: true property bool verticalHeaderVisible: true
property color selectedBorderColor: FluTheme.primaryColor
property color selectedColor: FluTools.colorAlpha(FluTheme.primaryColor,0.3)
property alias sourceModel: table_model
id:control id:control
color: FluTheme.dark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1) color: FluTheme.dark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1)
onColumnSourceChanged: { onColumnSourceChanged: {
@ -44,7 +47,7 @@ Rectangle {
item_loader_layout.cellItem = cellItem item_loader_layout.cellItem = cellItem
item_loader_layout.x = table_view.contentX + cellPosition.x item_loader_layout.x = table_view.contentX + cellPosition.x
item_loader_layout.y = table_view.contentY + cellPosition.y item_loader_layout.y = table_view.contentY + cellPosition.y
item_loader_layout.width = table_view.columnWidthProvider(column) item_loader_layout.width = header_horizontal.columnWidthProvider(column)
item_loader_layout.height = table_view.rowHeightProvider(row) item_loader_layout.height = table_view.rowHeightProvider(row)
item_loader.display = display item_loader.display = display
var obj =columnSource[column].editDelegate var obj =columnSource[column].editDelegate
@ -198,25 +201,8 @@ Rectangle {
ScrollBar.vertical: FluScrollBar{ ScrollBar.vertical: FluScrollBar{
id:scroll_bar_v id:scroll_bar_v
} }
columnWidthProvider: function(column) { syncView: header_horizontal
var w = columnSource[column].width syncDirection: Qt.Horizontal
if(!w){
w = columnSource[column].minimumWidth
}
if(!w){
w = d.defaultItemWidth
}
if(item_loader_layout.cellItem){
if(column === item_loader.column){
item_loader_layout.width = w
}
if(column === item_loader.column-1){
let cellPosition = item_loader_layout.cellItem.mapToItem(scroll_table, 0, 0)
item_loader_layout.x = table_view.contentX + cellPosition.x
}
}
return w
}
rowHeightProvider: function(row) { rowHeightProvider: function(row) {
if(row>=table_view.rows){ if(row>=table_view.rows){
return 0 return 0
@ -240,7 +226,7 @@ Rectangle {
} }
return h return h
} }
model: table_model model: table_sort_model
clip: true clip: true
onRowsChanged: { onRowsChanged: {
closeEditor() closeEditor()
@ -276,23 +262,14 @@ Rectangle {
return false return false
} }
color:{ color:{
if(item_table.isRowSelected){
return control.selectedColor
}
if(d.rowHoverIndex === row || item_table.isRowSelected){ if(d.rowHoverIndex === row || item_table.isRowSelected){
return FluTheme.dark ? Qt.rgba(1,1,1,0.06) : Qt.rgba(0,0,0,0.06) return FluTheme.dark ? Qt.rgba(1,1,1,0.06) : Qt.rgba(0,0,0,0.06)
} }
return (row%2!==0) ? control.color : (FluTheme.dark ? Qt.rgba(1,1,1,0.015) : Qt.rgba(0,0,0,0.015)) return (row%2!==0) ? control.color : (FluTheme.dark ? Qt.rgba(1,1,1,0.015) : Qt.rgba(0,0,0,0.015))
} }
Rectangle{
height: 18
radius: 1.5
color: FluTheme.primaryColor
width: 3
visible: item_table.isRowSelected && column === 0
anchors{
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: 3
}
}
MouseArea{ MouseArea{
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
@ -335,6 +312,36 @@ Rectangle {
return com_text return com_text
} }
} }
Item{
anchors.fill: parent
visible: item_table.isRowSelected
Rectangle{
width: 1
height: parent.height
anchors.left: parent.left
color: control.selectedBorderColor
visible: column === 0
}
Rectangle{
width: 1
height: parent.height
anchors.right: parent.right
color: control.selectedBorderColor
visible: column === control.columns-1
}
Rectangle{
width: parent.width
height: 1
anchors.top: parent.top
color: control.selectedBorderColor
}
Rectangle{
width: parent.width
height: 1
anchors.bottom: parent.bottom
color: control.selectedBorderColor
}
}
} }
} }
} }
@ -397,11 +404,29 @@ Rectangle {
anchors.left: scroll_table.left anchors.left: scroll_table.left
anchors.top: parent.top anchors.top: parent.top
visible: control.horizonalHeaderVisible visible: control.horizonalHeaderVisible
implicitWidth: syncView ? syncView.width : 0 implicitWidth: table_view.width
implicitHeight: visible ? Math.max(1, contentHeight) : 0 implicitHeight: visible ? Math.max(1, contentHeight) : 0
syncView: table_view
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
clip: true clip: true
columnWidthProvider: function(column) {
var w = columnSource[column].width
if(!w){
w = columnSource[column].minimumWidth
}
if(!w){
w = d.defaultItemWidth
}
if(item_loader_layout.cellItem){
if(column === item_loader.column){
item_loader_layout.width = w
}
if(column === item_loader.column-1){
let cellPosition = item_loader_layout.cellItem.mapToItem(scroll_table, 0, 0)
item_loader_layout.x = table_view.contentX + cellPosition.x
}
}
return w
}
delegate: Rectangle { delegate: Rectangle {
id:column_item_control id:column_item_control
readonly property real cellPadding: 8 readonly property real cellPadding: 8
@ -524,7 +549,7 @@ Rectangle {
maximumWidth = 65535 maximumWidth = 65535
} }
columnObject.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth) columnObject.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth)
table_view.forceLayout() header_horizontal.forceLayout()
} }
} }
} }
@ -687,14 +712,22 @@ Rectangle {
o.options = options o.options = options
return o return o
} }
function sort(order){ function sort(callback=undefined){
if(order === undefined){ if(callback){
table_view.model = table_model table_sort_model.setComparator(function(left,right){
}else{ return callback(table_model.getRow(left),table_model.getRow(right))
table_view.model = table_sort_model
table_sort_model.setSortComparator(function(left,right){
return order(table_model.getRow(left),table_model.getRow(right))
}) })
}else{
table_sort_model.setComparator(undefined)
}
}
function filter(callback=undefined){
if(callback){
table_sort_model.setFilter(function(index){
return callback(table_model.getRow(index))
})
}else{
table_sort_model.setFilter(undefined)
} }
} }
function setRow(rowIndex,obj){ function setRow(rowIndex,obj){

View File

@ -13,6 +13,9 @@ Rectangle {
property alias columns: table_view.columns property alias columns: table_view.columns
property bool horizonalHeaderVisible: true property bool horizonalHeaderVisible: true
property bool verticalHeaderVisible: true property bool verticalHeaderVisible: true
property color selectedBorderColor: FluTheme.primaryColor
property color selectedColor: FluTools.colorAlpha(FluTheme.primaryColor,0.3)
property alias sourceModel: table_model
id:control id:control
color: FluTheme.dark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1) color: FluTheme.dark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1)
onColumnSourceChanged: { onColumnSourceChanged: {
@ -45,7 +48,7 @@ Rectangle {
item_loader_layout.cellItem = cellItem item_loader_layout.cellItem = cellItem
item_loader_layout.x = table_view.contentX + cellPosition.x item_loader_layout.x = table_view.contentX + cellPosition.x
item_loader_layout.y = table_view.contentY + cellPosition.y item_loader_layout.y = table_view.contentY + cellPosition.y
item_loader_layout.width = table_view.columnWidthProvider(column) item_loader_layout.width = header_horizontal.columnWidthProvider(column)
item_loader_layout.height = table_view.rowHeightProvider(row) item_loader_layout.height = table_view.rowHeightProvider(row)
item_loader.display = display item_loader.display = display
var obj =columnSource[column].editDelegate var obj =columnSource[column].editDelegate
@ -199,25 +202,8 @@ Rectangle {
ScrollBar.vertical: FluScrollBar{ ScrollBar.vertical: FluScrollBar{
id:scroll_bar_v id:scroll_bar_v
} }
columnWidthProvider: function(column) { syncView: header_horizontal
var w = columnSource[column].width syncDirection: Qt.Horizontal
if(!w){
w = columnSource[column].minimumWidth
}
if(!w){
w = d.defaultItemWidth
}
if(item_loader_layout.cellItem){
if(column === item_loader.column){
item_loader_layout.width = w
}
if(column === item_loader.column-1){
let cellPosition = item_loader_layout.cellItem.mapToItem(scroll_table, 0, 0)
item_loader_layout.x = table_view.contentX + cellPosition.x
}
}
return w
}
rowHeightProvider: function(row) { rowHeightProvider: function(row) {
if(row>=table_view.rows){ if(row>=table_view.rows){
return 0 return 0
@ -241,7 +227,7 @@ Rectangle {
} }
return h return h
} }
model: table_model model: table_sort_model
clip: true clip: true
onRowsChanged: { onRowsChanged: {
closeEditor() closeEditor()
@ -277,23 +263,14 @@ Rectangle {
return false return false
} }
color:{ color:{
if(item_table.isRowSelected){
return control.selectedColor
}
if(d.rowHoverIndex === row || item_table.isRowSelected){ if(d.rowHoverIndex === row || item_table.isRowSelected){
return FluTheme.dark ? Qt.rgba(1,1,1,0.06) : Qt.rgba(0,0,0,0.06) return FluTheme.dark ? Qt.rgba(1,1,1,0.06) : Qt.rgba(0,0,0,0.06)
} }
return (row%2!==0) ? control.color : (FluTheme.dark ? Qt.rgba(1,1,1,0.015) : Qt.rgba(0,0,0,0.015)) return (row%2!==0) ? control.color : (FluTheme.dark ? Qt.rgba(1,1,1,0.015) : Qt.rgba(0,0,0,0.015))
} }
Rectangle{
height: 18
radius: 1.5
color: FluTheme.primaryColor
width: 3
visible: item_table.isRowSelected && column === 0
anchors{
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: 3
}
}
MouseArea{ MouseArea{
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
@ -336,6 +313,36 @@ Rectangle {
return com_text return com_text
} }
} }
Item{
anchors.fill: parent
visible: item_table.isRowSelected
Rectangle{
width: 1
height: parent.height
anchors.left: parent.left
color: control.selectedBorderColor
visible: column === 0
}
Rectangle{
width: 1
height: parent.height
anchors.right: parent.right
color: control.selectedBorderColor
visible: column === control.columns-1
}
Rectangle{
width: parent.width
height: 1
anchors.top: parent.top
color: control.selectedBorderColor
}
Rectangle{
width: parent.width
height: 1
anchors.bottom: parent.bottom
color: control.selectedBorderColor
}
}
} }
} }
} }
@ -398,11 +405,29 @@ Rectangle {
anchors.left: scroll_table.left anchors.left: scroll_table.left
anchors.top: parent.top anchors.top: parent.top
visible: control.horizonalHeaderVisible visible: control.horizonalHeaderVisible
implicitWidth: syncView ? syncView.width : 0 implicitWidth: table_view.width
implicitHeight: visible ? Math.max(1, contentHeight) : 0 implicitHeight: visible ? Math.max(1, contentHeight) : 0
syncView: table_view
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
clip: true clip: true
columnWidthProvider: function(column) {
var w = columnSource[column].width
if(!w){
w = columnSource[column].minimumWidth
}
if(!w){
w = d.defaultItemWidth
}
if(item_loader_layout.cellItem){
if(column === item_loader.column){
item_loader_layout.width = w
}
if(column === item_loader.column-1){
let cellPosition = item_loader_layout.cellItem.mapToItem(scroll_table, 0, 0)
item_loader_layout.x = table_view.contentX + cellPosition.x
}
}
return w
}
delegate: Rectangle { delegate: Rectangle {
id:column_item_control id:column_item_control
readonly property real cellPadding: 8 readonly property real cellPadding: 8
@ -525,7 +550,7 @@ Rectangle {
maximumWidth = 65535 maximumWidth = 65535
} }
columnObject.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth) columnObject.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth)
table_view.forceLayout() header_horizontal.forceLayout()
} }
} }
} }
@ -688,14 +713,22 @@ Rectangle {
o.options = options o.options = options
return o return o
} }
function sort(order){ function sort(callback=undefined){
if(order === undefined){ if(callback){
table_view.model = table_model table_sort_model.setComparator(function(left,right){
}else{ return callback(table_model.getRow(left),table_model.getRow(right))
table_view.model = table_sort_model
table_sort_model.setSortComparator(function(left,right){
return order(table_model.getRow(left),table_model.getRow(right))
}) })
}else{
table_sort_model.setComparator(undefined)
}
}
function filter(callback=undefined){
if(callback){
table_sort_model.setFilter(function(index){
return callback(table_model.getRow(index))
})
}else{
table_sort_model.setFilter(undefined)
} }
} }
function setRow(rowIndex,obj){ function setRow(rowIndex,obj){