Telerik MVC Grid groups with key, display, and sort values? - telerik

I'm running a grid with Ajax binding with added groups:
.Groupable(grouping => grouping
.Groups(groups =>
{
for (int i = 0; i < TagGroups.Count; i++)
{
groups.Add(c => c.Tags[i].Name);
}
})
)
This is grouping the data by the Name property. In essence, the Name property is being used for three jobs. It is acting as the group key, it is the displaying value, and is used to sort the groups alphabetically.
I want to specify the property for each of these jobs. I want the Id property to act as the group key, the Name property to act as the display value, and the Order property to act as the sort value numerically instead of alphabetically.
If this is a tall order, I can live with the Name property as the group key and display value, but I need to specify the Order property as the sort value. Any thoughts? I'd prefer not tinkering with back-end data with Linq or such, because It makes a lot of sense to just configure a Telerik Grid to do this.

Both Name & Order are bound columns in the grid. Use only Order in the Groupable list. Then in your grid DataBound(), replace each order with the corresponding Name property.

Related

How to Select multiple related columns in add calculated fields in Quicksight parameter using ifelse?

I have a parameter 'type' in a table and it can have multiple values as follows -
human
chimpanzee
orangutan
I have 3 columns related to each type in the table -
human_avg_height, human_avg_weight, human_avg_lifespan
chimpanzee_avg_height, chimpanzee_avg_weight, chimpanzee_avg_lifespan
orangutan_avg_height, orangutan_avg_weight, orangutan_avg_lifespan
So if i select the type as human, the quicksight dashboard should only display the three columns -
human_avg_height, human_avg_weight, human_avg_lifespan
and should not display the following columns -
chimpanzee_avg_height, chimpanzee_avg_weight, chimpanzee_avg_lifespan
orangutan_avg_height, orangutan_avg_weight, orangutan_avg_lifespan
I created the parameter type and in the add calculated fields I am trying to use ifelse to select the columns based on the parameter selected as follows -
ifelse(${type}='human',{human_avg_height}, {human_avg_weight}, {human_avg_lifespan},{function})
I also tried -
ifelse(${type}='human',{{human_avg_height}, {human_avg_weight}, {human_avg_lifespan},{function}})
And -
ifelse(${type}='human',{human_avg_height, human_avg_weight, human_avg_lifespan},{function}})
But none of it is working. What am i doing wrong ?
One way to do this would be to use three different calculated fields, one for all the heights, one for weights and one for lifespan. The heights one would look like this:
ifelse(
${type}='human',{human_avg_height}, ifelse(
${type}='chimpanzee', { chimpanzee_avg_height}, ifelse(
${type}='orangutan',{ orangutan_avg_height},
NULL
)))
Make another calculated field for weights and lifespan and then add these calculated fields to your table, and filter by type.
To make it clear to the viewer what data is present, edit the Title of the visual to include the type:
${type} Data
You have to create one calculated field for each measure using the ifelse with the type to choose the correct vale, but is not necessary to create inner ifelse as skabo did, the if else syntax is ifelse(if, then [, if, then ...], else) so you can define the calculated fields as follows:
avg_height = ifelse(${type}='human', {human_avg_height}, ${type}='chimpanzee', {chimpanzee_avg_height},${type}='orangutan', {orangutan_avg_height}, NULL)
avg_weight = ifelse(${type}='human', {human_avg_weight}, ${type}='chimpanzee', {chimpanzee_avg_weight},${type}='orangutan', {orangutan_avg_weight}, NULL)
avg_lifespan = ifelse(${type}='human', {human_avg_lifespan}, ${type}='chimpanzee', {chimpanzee_avg_lifespan},${type}='orangutan', {orangutan_avg_lifespan}, NULL)
Then use those calculated fields in your visuals.

ag-grid modify Row Group's Header name

I'm using ag-grid to display a table which has a Row Grouping.
The column that I group by is invisible since its value holds no meaning.
So for example, I will have the following (fully collapsed) table:
---------------------------------
| H1 H2 H3 |
----------------------------------
| > groupId1 (1) |
----------------------------------
| > groupId2 (5) |
----------------------------------
As you see the grouping is done by user-unfriendly ID which is not reflected at all in the Column Definitions. I would like to change groupId1 / groupId2 to a user-friendly text that is assigned dynamically according to the content of the group rows.
I am using React.
I am using ag-Grids examples as a starting point, the following example embodies the problem I'm facing: (eg: https://plnkr.co/edit/VM59gScPD55PhX4y4JBj?p=preview)
It has row grouping
The grouping is done by a column that is invisible (country)
I would like to change the country name dynamically into a different value that's derived from the values of the inner row.
Thanks for your time. :)
You can also rename the rowGroup header of ag-grid by using this simple prop
autoGroupColumnDef
<AgGridReact
columnDefs={columnDefs}
rowData={rowData}
autoGroupColumnDef={{
headerName: 'Name'
}}
/>
A colleague helped me at the end, his solution was:
valueFormatter: ({ value, data }) => 'something ' + value
inside the colDef of my group, and the value to be displayed as the header is sent inside 'data'.
He said that cellRenderer is an overkill for a simple task like this.
You can pass additional params about group cell renderer and customize it like this -
colDef = {
// set the cell renderer to 'group'
cellRenderer:'agGroupCellRenderer',
// provide extra params to the cellRenderer
cellRendererParams: {
innerRenderer: myInnerRenderer, // provide an inner renderer
}
...
};
You should be then able to display any text based on custom logic using the myInnerRenderer implementation.
Here is an example from ag-grid docs. Check the Group Renderer C implementation

Different value and display value for option rows

I have a need to specify different value and display values in an option row (PushRow and MultipleSelectorRow). By display values I mean the values that are displayed in the option selection view controller (not the concatenated list of selected values displayed in the form).
I know this can be done by using a custom class that conforms to Hashable and setting the options property of the row to an array of such class instances.
$0.options = [
MyStruct(value: "1", displayValue: "one"),
MyStruct(value: "2", displayValue: "two"),
MyStruct(value: "3", displayValue: "three")]
However this results in the value of the so configured row being of type MyStruct when getting the form values using form.values as opposed to the actual value I'm interested in being MyStruct.value. This creates the needless complexity of having to map the form values accordingly.
I was wondering if there is a more desirable approach to achieve this? I.e. the values of the row remain a simple data type (say String or Int) but the displayed values in the option selection view controller can be customised.

DataTable.RowFilter using List results?

I need to keep the original DataTable and filter it based on list values. I've tried to hide rows that don't match up to the list but it doesn't work instantly. I don't want to copy the list to another dataTable and bind my dataGridView to is cause i have too much tied up to the original DataTable. Filtering only works for a few conditions but the list is holds only the values that are needed. Is there a LINQ solution to this? C# only please. This is how I got my list. There is another dataGridView that holds primary key for the datatable that I need to filter. It's key is held in a comboBox.
DataTable MainTable = MainDataSet.Tables["MyTable"];
DataTable lookupTable = lookupDataSet.Tables["MyLookupTable"];
var List = (from x in lookupTable.AsEnumerable()
where x.Field<string>("kAutoInc") == comboBox.SelectedValue.ToString()
select x.Field<int>("Pct")).ToList();
var a = MainTable.AsEnumerable().Where(r =>
List .Any(id => id == r.Field<int>("Pct")));
This gives me values of int 30, 40, 50, 60...
The DataGridView has a matching column "Pct" that I need to filter rows that only contain these values. I know it seems easy but I just can't seem to get it to work.
Please use DataView instead.
dataview dv=new dataview(datatable);
dv.filter=string.format("column1={0}","value1");
Like that.

Dojo DataGrid (EnhancedGrid) sorting issue

I have a DataGrid, created programmatically and loaded from ItemFileReadStore.
I want the first column of DataGrid always be sorted in descending order and disabled for user for sorting. Any other column should be available for sorting as a secondary sortable.
I don't want to give users such a powerful(complex and confusing) feature, as sorting by multiple columns, because there are too many columns in my grid.
So, it should be one sortable column for user and another one "already sorted unsortable" column in fact.
Does anyone know how can this be achieved?
Thanks.
To sort the first column add "sortInfo:-1" when you created your object.
To allow sorting the grid from any other columns but not the first you need to overwrite the function canSort.
To create you grid should now look like this .
dijit.grid.DataGrid({
canSort: function (sortInfo) {
if (Math.abs(sortInfo) == 1){
return false;
} else {
return this.inherited("canSort", arguments);
}
},
sortInfo: -1, .....
If you need to sort on more as one column you need dojox.grid.enhanced.plugins.NestedSorting.
http://dojotoolkit.org/reference-guide/1.7/dojox/grid/EnhancedGrid/plugins/NestedSorting.html

Resources