ag-grid:如果在一定间隔时间内刷新网格或刷新页面,则如何设置和检索ag-grid排序列的状态。
这里的网格行为是,网格每隔一定间隔刷新一次,因此需要保存排序列的状态以保持网格或页面刷新的一致状态。请帮助您如何保存和检索已排序列的状态。
grid.component.ts
class ProductCategoryTableViewCell: UITableViewCell {
// @IBOutlet weak var view: UIView!
@IBOutlet weak var bg: UIView!
@IBOutlet weak var categoryLabel: UILabel!
var category: String!
override func awakeFromNib() {
super.awakeFromNib()
configureUi()
}
override func prepareForReuse() {
super.prepareForReuse()
// Set your default background color, title color etc
configureUi()
}
func configureUi() {
let cornerRadius: CGFloat = 5
bg.layer.cornerRadius = cornerRadius
bg.layer.borderWidth = 1
bg.clipsToBounds = true
if Theme.selectedTheme == 1 {
if #available(iOS 11.0, *) {
// view.backgroundColor = UIColor.red //Theme.backgroundColor
contentView.backgroundColor = UIColor.clear
bg.backgroundColor = Theme.textFieldBackgroundColor
bg.layer.borderColor = Theme.accentColor?.cgColor
categoryLabel.backgroundColor = Theme.textFieldBackgroundColor
categoryLabel.textColor = Theme.textFieldTextColor
} else {
// Fallback on earlier versions
// view.backgroundColor = Theme.backgroundColorRgb
bg.backgroundColor = Theme.textFieldBackgroundColorRgb
bg.layer.borderColor = Theme.accentColorRgb.cgColor
categoryLabel.backgroundColor = Theme.textFieldBackgroundColorRgb
categoryLabel.textColor = Theme.textFieldTextColorRgb
}
} else if Theme.selectedTheme == 2 {
if #available(iOS 11.0, *) {
// view.backgroundColor = Theme.backgroundColor2
bg.backgroundColor = Theme.textFieldBackgroundColor2
bg.layer.borderColor = Theme.accentColor2?.cgColor
categoryLabel.backgroundColor = Theme.textFieldBackgroundColor2
categoryLabel.textColor = Theme.textFieldTextColor2
} else {
// Fallback on earlier versions
// view.backgroundColor = Theme.backgroundColorRgb2
bg.backgroundColor = Theme.textFieldBackgroundColorRgb2
bg.layer.borderColor = Theme.accentColorRgb2.cgColor
categoryLabel.backgroundColor = Theme.textFieldBackgroundColorRgb2
categoryLabel.textColor = Theme.textFieldTextColorRgb2
}
}
}
}
grid.html
ngOnInit() {
this.getComponentData();
this.userService.UserWellUpdated.subscribe((next) => {
console.log("Well data Refreshing");
let rowData: any;
let newHeaderValues: string[];
........
getComponentData() {
this.gridOptions.enableSorting = true;
this.gridOptions.api.getSortModel();
this.columns = this.tab1Col;
type colFormat = Array<{ headerName: string, width: number, field: any, unSortIcon: any }>;
let colWidth: number;
let rowData: any;
.........
BuildSurveysGridData(rowData: any) {
type colFormat = Array<{ headerName: string, width: number, field: any, unSortIcon: any }>;
let colWidth: number;
let colRows: colFormat = [];
this.headerValues = this.headerOpt;
for (let a = 0; a < this.headerOpt.length; a++) {
colRows.push({
headerName: this.headerOpt[a],
width: colWidth,
field: this.headerOpt[a],
unSortIcon: false
})
this.BuildSurveyGridSortingColumns(colRows, a)
.........
BuildSurveyGridSortingColumns(colRows:any, a: number) {
if (this.columns == "One") {
if (a < 3) {
colRows[a]['unSortIcon'] = true;
colRows[a]['sortingOrder'] = ['asc', 'desc'];
if (a == 2 || a == 0) {
colRows[a]["comparator"] = this.valueComparer;
if (a == 2) {
colRows[a]['sort'] = 'asc';
}
}
.........
valueComparer(val1, val2) {
if (val1 == undefined || val2 == undefined || val1.value == undefined || val2.value == undefined)
return 0;
return val1.value - val2.value;
}