How to disable pivot grid ordering in devexpress? - asp.net

I am new in devexpress. I have data list to bind pivot grid. And I order my data list from SQL command. But as default pivot grid reoreder my data list to show.
I don't desire to reordered my list. Is it possible to ignore default ordering of pivot grid or some columns?

Source: How to disable default ordering of pivot grid ?
The cause of this behavior is that he pivot has it's own data engine
and has to sort data. Using the provided solution, you can sort field
values in a custom way, for example, using the order from the data
source.
Go through DevExpress thread - Disable Sorting in PivotGrid RowArea to more detailed information about the required functionality.
You can use the ASPxPivotGrid.CustomFieldSort event to sort data manually.
It is necessary to sort data manually by handling the ASPxPivotGrid.CustomFieldSort event. Do your calculation of sorting and grouping at this event. Below, I have posted a code snippet, demonstrating how to disable sorting:
private void pivotGridControl1_CustomFieldSort(object sender, PivotGridCustomFieldSortEventArgs e)
{
e.Result = e.ListSourceRowIndex1.CompareTo(e.ListSourceRowIndex2);
e.Handled = true;
}
References:
ASPxPivotGrid remove custom sort/order

Related

Vaadin 14 Grid Component Column containing checkbox does not sort

I am using Vaadin 14 grid. This grid contains a number of columns. A few of them need to represent boolean values, hence we use a checkbox component inside that column. This is done by using grid.addComponentColumn method. The text related columns a just added using grid.addColumn
Now we want to enable multisort on the grid. By default the sorting indicators (up/down arrow) in the header are shown for the text based columns but not for the boolean values .
After adding sorting to the boolean column /component column (addComponentColumn(...).setSortable(true) the sorting indicators in the headers are shown, but the sorting itself is not performed when changing the sort direction (none / asc / desc) using the arrows in the header.
How can I make this work?
Thanks in advance!
When you have custom logic for what's rendering in a column, then you also need to explicitly configure how sorting should be handled for that column.
If you're using in-memory data, then you do that using Column.setComparator. If you're using a backend data source, then you should instead use Column.setSortProperty and also ensure that the data provider actually considers the contents of Query.getSortOrders.
You can see an example of this in practice at https://cookbook.vaadin.com/sort-with-renderer.

DevExpress:How to programmatically remove a column from XtraReport?

I have a Web application with XtraReport report. The report has several columns.
Depending on a certain condition, in certain situations I do not need one of the columns to exist. What is a best way to programmatically remove it? I need not to ‘make the column invisible’, but remove it. The space that the column occupied before the removal should be distributed evenly between the other columns.
A proper solution is to temporary remove the unnecessary XRTableCell from the XRTableRow.Cells collection...
Review the http://www.devexpress.com/issue=Q216567 discussion in the DevExpress support center. Hope this helps.
The easiest way to achieve this is to remove the cell from the row (for example on the report BeforePrint event). You should also wrap it in the suspend-resume layout code for the table itself:
private void TableReport_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
xrTable1.SuspendLayout();
xrTableRow1.Cells.Remove(xrTableCell1);
xrTable1.PerformLayout();
}
you can use dispose the cell
If CEHide.Checked = True Then
XrTableCell2.Dispose()

Gridview Edit not working after Sorting ASP.NET

I am using C#,ASP.NET
I have a Gridview for which I have provided Sorting, Edit functionality. I am not able to perform EDIT when I perform Sorting. After sorting edit is set on some other row. I think there is some problem with the index it is taking..
Can any one help me how to fix this..
Regards
sbmarya
I think the issue is that the sorting is using a different call/datasouce than the editing. So in the RowEditing event I am getting an index relative to the sort order (either ASC() or DESC()). But then I am binding using getUsers() which is returning the data in a different order.
What I did is I stored some kind of a flag(Value) in ViewState to indicate what sort order I am in and made use of that when I am binding in the Editing event, so that I can call the right method to return the same datasource.
Regards,
sbmarya
I faced this problem as well. This is how I fixed it. (In my example the gridview is sorted on a column called submit date).
a. When the underlying dataTable of the gridview is crated and sorted store it in a session variable. The trick is, before storing to a session variable make sure you store the sorted view.
dt.DefaultView.Sort = "Submit Date" + " " + "DESC";
GridView1.DataSource = dt;
GridView1.DataBind();
Session["gridViewData"] = dt.DefaultView.ToTable(); //Only storing dt will not have the sorted table stored in session.
b. next, perform all edit/update operation using the dataTable stored in session in the above step. It will always come up in proper sorted order and you will not see the issue of row index changing unexpectedly after update.

How do I add columns and rows dynamically to an asp.net 1.1?

I am working on an ASP.NET 1.1 project where the requirement is to create a matrix table where the number of rows and the number of columns are determined by two separate datasets and can vary. Once the matrix is created the page has several buttons that do postbacks that need the data and any modifications made to a cell in the matrix table to be retained.
The <asp:DataGrid />is the obvious option but how do I add columns dynamically to the control?
I am also considering dynamically building <asp:table /> control on the fly but I am not really sure if this is the way to go.
A problem I have with datagrids is that they blindly bind to a dataset. The table I am creating has the first column as the sum and the second one as the weighted average of the subsequent column data. There is also a grouping of the columns.
In this scenario is it better to use a table server control and build the entire thing or do this in a datagrid ?
you can programatically add columns to a datagrid like that :
BoundColumn linkColumn = new BoundColumn();
linkColumn.DataField = "UserID";
linkColumn.DataFormatString = "<a href='UserDetails.aspx={0}'>User Details</a>";
linkColumn.HeaderText = "User Details";
DataGrid1.Columns.Add(linkColumn);
programmatically adding rows is adding rows to datasource that you bind to datagrid, isn't it ?
In my opinion using grid is simpler, grid manages binding and formatting for you. But using table gives you ability to manage cells to you.
Not sure what is the bottleneck. It is possible to retain values in dataset using viewstate or session.
You can create a instance of a column and what you need and add to data grid.Check google for samples instead of posting here,on google you would find sample of how to work with a data grid.Data grid is better.

a ListView, a LinqDataSource, linq-to-sql and ordering

So I'm writing a page which does some reporting and it's pretty dynamic, the user has the ability to group data and sort columns. I've been able to get my dynamic grouping down and then the sorting except now my generated linq-to-sql sql order by statement is backwards from what I want it to be. I think I need to figure out how to get at the Result returned from the LinqDataSource when the Sorting event is fired in the ListView so that I can then append my grouping order by clauses.
Currently I'm overriding the LinqDataSource selecting event to provide it's result and do the dynamic grouping there, but then the Result is modified by the Sort on the listview and I was thinking there must be some way to get at that result during the Sorting or Sorted event.
Any insight would be appreciated, in the meantime I will be attempting to figure this out myself.
Awesome I think I found my answer, set AutoSort to false on my LinqDataSource and then sort the data myself, since I'm already sorting myself for the other data.
You can use Linq to manipulate the results of your queries (IEnumerables) based on user inputs. For example (very pseudocode event handler follows):
public void OnUserClickNameColumn(object sender, EventArgs e){
var data = DataProvider.RetrieveAllUsers();
// switch between sorting asc and desc when user clicks on a column head
SessionHelper.CurrentUser.NameColumnSort = !SessionHelper.CurrentUser.NameColumnSort;
if(SessionHelper.CurrentUser.NameColumnSort) // true = sort asc else sort desc
UserDataGrid.DataSource = data.OrderBy(x=>x.Name);
else
UserDataGrid.DataSource = data.OrderByDescending(y=>y.Name);
}

Resources