Thanks for info.
Played with it a bit and managed to add it via code in runtime.
The only moment that’s not yet clear is how to use sorting, should I sort .itemsSource manually, is there a callback I can use for that (couldn’t find one) or should we use data binding some way (couldn’t find anything similar to cell-binding-path in code)
Here is a code snippet I use for testing (I’m using it in uitoolkit runtime).
...
void Start()
{
_list = new List<ListItem>()
{
new ListItem
{
f1 = "1_1",
f2 = "1_2",
f3 = "1_3",
},
new ListItem
{
f1 = "2_1",
f2 = "2_2",
f3 = "2_3",
},
new ListItem
{
f1 = "3_1",
f2 = "3_2",
f3 = "3_3",
}
};
uiDocument.rootVisualElement.Q<MultiColumnListView>().itemsSource = _list;
var columns = new Columns();
columns.Add(new Column
{
name = "column1",
title = "title1",
bindCell = (x, y) => { OnBindCell(x, y, 0); },
makeCell = OnMakeCell,
sortable = true,
});
columns.Add(new Column
{
name = "column2",
title = "title2",
bindCell = (x, y) => { OnBindCell(x, y, 1); },
makeCell = OnMakeCell,
});
columns.Add(new Column
{
name = "column3",
title = "title3",
bindCell = (x, y) => { OnBindCell(x, y, 2); },
makeCell = OnMakeCell,
});
var mc = new MultiColumnListView(columns);
mc.itemsSource = _list;
uiDocument.rootVisualElement.Add(mc);
}
private VisualElement OnMakeCell()
{
var ve = new VisualElement();
var label = new Label();
ve.Add(label);
return ve;
}
private void OnBindCell(VisualElement ve, int index, int columnIndex)
{
if (columnIndex == 0) ve.Q<Label>().text = _list[index].f1;
if (columnIndex == 1) ve.Q<Label>().text = _list[index].f2;
if (columnIndex == 2) ve.Q<Label>().text = _list[index].f3;
}
...