How to only show specific columns in ui-grid.js - javascript

I have json data (REST response) with many (partly nested) parameters but only want to show specif ones.
How to hide all and enable only specific ones? Currently all parameters are shown as columns.
So I do not want to hide one-by-one by excludeParameters or columnDef visible = false (because the list of parameters can be different based on REST response).
Do you have any idea?
My intension is to change the default visibility to false and only the wanted parameters to true (via columnDef visible). Any solution for that?
Thanks in advance,
Chris

My table options looks like this
$scope.tableOptions= {
data : [],
columnDefs :[
{ field : 'firstName'},
{ field : 'middelName'},
{ field : 'lastName' }
]
}
and I am using the directive as
<div ui-grid="tableOptions"></div>
the data will be populated inside the data field of $scope.tableOptions once the rest api fetches result
Each Json object in my case is having more than 10 fields but the table is only showing three fields which I have defined in columnDefs

Related

Dynamically add options to select2 with a POST request

I am trying to add options dynamically to a multiselect form using Select2. Backend is Ruby on Rails and I have defined a create method for the "genre" model (it's a movie db) in question that takes input as json and adds to the database.
The code below works, but only somewhat :)
when I want to add a new genre "abc" - first of all, the select2 drop-down shows "no results" (and doesn't give the option to add the genre).
However in the BACKEND - the entry is actually created and available for future manipulations. In addition - there isn't just one genre "abc" added, but actually one "a", another one "ab", and a third one "abc".
So two things I need to fix - and I don't know enough JS to know how... :/ ...
how do I ensure that only ONE genre - "abc" is created?
how do I make sure that the genre is shown during creation, and selected properly when I update the form?
Code:
$("#genre-select").select2({
tags: true,
tokenSeparators: [","],
createTag: function (params) {
let term = $.trim(params.term);
$.post("/genres.json", { genre: { name: term } });
},
});

Update a third component on focus/click based on the selected values of two other components

My form.io panel looks like this JSON. I have a panel wherein there are components such as dropdowns & textfields.
I am trying to get a calculated value to a textfield component based on the selected values on two other components. The value should be populated either at the time of getting focus or click event on the textfileld component.
I have tried to use calculateValue on the textfield but nothing seems to happen. No errors as well. The component with key dental in the link provided above is where you will find the javascript i have tried.
In form.io's calculateValue, you need to be setting value in order to update the field.
value=data.param1+data.param2;
I've got an example for a text field here that worked for me immediately:
{
"label": "Select + Select1",
"tableView": true,
"calculateValue": "value=data.select+data.select1",
"key": "textText2",
"type": "textfield",
"input": true
},
You may also be running into issues because of how you're getting your data values. data. is the recommended way to get other data values in calculateValue.

Power BI SDK don't get or set filters when "all filters" is selected on online report

I'm trying to set dynamically filters from JS using Power BI SDK.
When I check on Power BI service the filters to "select all" 
then in my JS code  get filters as bellow 
rapport.getFilters().then(data => {
console.log("filters data", data)
....
I'm getting an empty array :
Secondly when I try to set filter using setFilters API nothing happens
 
report.setFilters(filters)
Here's what I send in 'filters'
My code works only in one case:
When I go to power bi service and uncheck selectAll then check manually one by one the filters.
In this case , when I setFilters the embedded view is getting updated.
But in my case I'm generating reports automatically so I can't go to PBI online and check every filter, I should keep default "select all" checked and set filter from front-end.
Any solution to set filters programmatically with default checked "selected all " ?
The response you are getting by using getFilters() seems correct.
To set filters programmatically with default checked as "Select all", Please use below code.
// Create a filter
const filter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "<TABLE-NAME>",
column: "<COLUMN-NAME>"
},
operator: "All",
values: []
};
// It is recommended to use the updateFilters API to apply filters
report.updateFilters(models.FiltersOperations.Add, [filter]);
For more info about creating and applying filters, refer the docs

How to implement initial sorting in SAP UI5 Smart Table

I have a smart table, with some custom columns inside it. I would like to sort the table initially based on a certain field, how do I achieve it?
Till now I have tried the following, but it didn't work.
var oSmartTableBatches = this.getView().byId("sapAffectedBatchesSmartTable2");
oSmartTableAlerts.applyVariant({
sort: {
sortItems: [{
columnKey: "FieldName",
operation: "Descending"
}]
}
});
I have also tried annotating the entity set with Presentation Variant
<Annotation Term="com.sap.vocabularies.UI.v1.PresentationVariant">
<Record>
<PropertyValue Property="SortOrder">
<Collection>
<Record>
<PropertyValue Property="Property" PropertyPath="FieldName"/>
<PropertyValue Property="Descending" Boolean="true"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Annotation>
I am using odata v2 model.
I also tried using beforeRebindTable function add a sorter, however it breaks the table personaliation dialog, and grouping and filtering doesn't work on table anymore.
The sorter must be an array of sap.ui.model.Sorter objects, see the documentation.
That applyVariant is only for showing the sorted column in P13N dialog.
The annotation that you used only applied on Grid tables and not responsive tables!
If you want to apply initial sorting you need to have the following event handler:
// define this variable in onInit function or in the controller class level
initView: true,
// smart table event handler
onBeforeRebindTable: function (oEvent) {
var mBindingParams = oEvent.getParameter("bindingParams");
if(this.initView){
// to apply the sort
mBindingParams.sorter = [new sap.ui.model.Sorter({ path: "FieldName", descending: true})];
// to short the sorted column in P13N dialog
var oSmartTable = oEvent.getSource();
oSmartTable.applyVariant({
sort: {
sortItems: [{
columnKey: "FieldName",
operation: "Descending"
}]
}
});
// to prevent applying the initial sort all times
this.initView = false;
}
},
This code sorts the data only when the app is loaded or if user presses on the browser refresh button!
Don't forget to keep the line mBindingParams.sorter = [new sap.ui.model.Sorter({ path: "FieldName", descending: true})]; inside a if condition, otherwise each time that user applies a sort you will overwrite it.
This condition also is possible:
if(mBindingParams.sorter.length === 0)
But in this case user cannot remove the sort conditions. Therefore when he or she removes all sorts in P13N dialog, not only in the initialization time, but in such kind of condition also the initial sort order will be applied!

dijit form select disregards sorting of dojo store memory datasource

I'm using a dojo store memory as a datasource for dijit form select. The problem I'm having is that the select control ignores the sort I've set on the data store and instead sorts data on the label field. I'm trying this:
mhusStore = new Memory({ data: data, idProperty: "MHID", sort: [{ attribute: "SegIDOrder", descending: false }] }); //verified the sort is on SegIDOrder in debug mode (it also comes out of the db this way
this.selectUSMAS.set("labelAttr", "MHID");
//this.selectUSMAS.set("sort", "SegIDOrder");//tried this no result
this.selectUSMAS.set("store", mhusStore);
any ideas how I can get the select to use the order of the memory store?
Thanks
already answered here:
How to change order of elements in a dijit.form.Select
this.selectUSMAS.set("sortByLabel", false);

Categories