void InitSelectedItemByUsingSelectedValue() { var enumerable = ItemsSource as IEnumerable; if (enumerable == null) { return; } var selectedValuePath = SelectedValuePath; if (selectedValuePath == null) { return; } var selectedValue = SelectedValue; foreach (var data in enumerable) { if (data == null) { continue; } var propertyPath = new PropertyPath(selectedValuePath); propertyPath.Walk(data); var propertyValue = propertyPath.GetPropertyValue(); if (selectedValue == propertyValue || (selectedValue != null && selectedValue.Equals(propertyValue))) { SelectedItem = data; return; } } }
void ReRender() { if (ItemsSource == null) { return; } var records = ItemsSource as IEnumerable; if (records == null) { throw new ArgumentException("Mustbe implement 'IEnumerable':" + nameof(ItemsSource) + "@ItemsSource.Type:" + ItemsSource?.GetType().FullName); } ClearVisualChilds(); ClearLogicalChilds(); var table = new HtmlElement("table", "ui celled table"); AddLogicalChild(table); table.AddVisualChild(_thead = new HtmlElement("thead")); _thead.AddVisualChild(_thead_first_tr = new HtmlElement("tr")); foreach (var columnInfo in Columns) { _thead_first_tr.AddVisualChild(columnInfo); } table.AddVisualChild(_tbody = new HtmlElement("tbody")); foreach (var itemData in records) { var tr = new HtmlElement("tr"); foreach (var columnInfo in Columns) { var td = new HtmlElement("td"); if (columnInfo.EditorType == DataGridCellEditorType.Text) { var propertyPath = new PropertyPath(columnInfo.Name); propertyPath.Walk(itemData); var cellValue = propertyPath.GetPropertyValue(); td.InnerHTML = cellValue?.ToString(); } else { throw new NotImplementedException(columnInfo.EditorType.ToString()); } //var bindingInfo = new BindingInfo //{ // Source = itemData, // SourcePath = columnInfo.Name, // BindingMode = BindingMode.OneWay, // Target = td, // TargetPath = nameof(td.InnerHTML) //}; //bindingInfo.Connect(); tr.AddLogicalChild(td); } _tbody.AddLogicalChild(tr); tr.On("click", () => { MarkSelectedRow(tr); }); var data = itemData; tr.On("click", () => { RaiseEvent_ItemClicked(data); }); } var me = this; OnSelectedItemChanged(); Wrap(me, table._root); }