Если вы можете сделать предположение, что все дети являются либо узлами элементов, либо текстовыми узлами, то это одно из решений.
Чтобы все дочерние текстовые узлы представляли собой набор jquery:
$('selector').clone().children().remove().end().contents();
Чтобы получить копию исходного элемента с удаленными дочерними элементами:
$('selector').clone().children().remove().end();
Вот как я это делаю: «Я делаю из сетки, чтобы сохранить все это внутри класса, поэтому я прикрепляю к обработчикам событий внутри
присоединиться к сортировочному событию
dataGrid.Sorting += new DataGridSortingEventHandler(SortHandler);
внедрить метод (я делаю это в полученном классе)
void SortHandler(object sender, DataGridSortingEventArgs e)
{
DataGridColumn column = e.Column;
IComparer comparer = null;
//i do some custom checking based on column to get the right comparer
//i have different comparers for different columns. I also handle the sort direction
//in my comparer
// prevent the built-in sort from sorting
e.Handled = true;
ListSortDirection direction = (column.SortDirection != ListSortDirection.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending;
//set the sort order on the column
column.SortDirection = direction;
//use a ListCollectionView to do the sort.
ListCollectionView lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(this.ItemsSource);
//this is my custom sorter it just derives from IComparer and has a few properties
//you could just apply the comparer but i needed to do a few extra bits and pieces
comparer = new ResultSort(direction);
//apply the sort
lcv.CustomSort = comparer;
}