Programatically add custom field to views not show up? - view

I'm adding a new fields to my views through my custom module.
When I open up the views page UI, the field is not show up. However, If I edit the view on UI and click add field, I can see my custom field is available to add.
My question, how can I add automatically that field to the list of fields to display on the views?
function mymodule_views_default_views() {
...
$handler->display->display_options['fields']['myfield']['id'] = 'fieldname';
$handler->display->display_options['fields']['myfield']['table'] = 'databaseTableName';
$handler->display->display_options['fields']['myfield']['field'] = 'fieldname';
...
}

Related

Magento 2 How to pass js variable to controller and then call template with custom code?

I need dynamically change custom attribute on the configurable page when I click to the swatch color attribute. On this purpose I programmatically created custom attributes with options on the admin panel, where I can save for every product his own custom attributes.
I figure out how to call my custom attributes on simple products but I can't to do this with configurable product.
I see when I change color attribute - price is changed for every simple product([it's default thing), how to do same but with my custom attributes?
I have one idea but I don't know how this one implement. So I know how to get current product id when you clicked on the color attribute(through js code) then I need pass this id data to the controller via ajax. I need to know how exactly to do this, how to pass js data through ajax to controller and then call needed block on the category page every time when I click on the color attribute? ? When I will be know how to do that I get with this id data - custom attribute values and call this template in the needed place.
Code below is that what call custom attributes on the configurable product, but it's call all attributes for all simple products included in the configurable product. I need call these attributes for current product every time when I cliked on the color attribute. For example: if I click on the black color (which related to the product with id 123 ) I get custom block with custom attributes without reloading page(like price).color attributes
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$product_id = $product->getId();
$configProduct = $objectManager-
>create('Magento\Catalog\Model\Product')->load($product_id);
$configurable = $configProduct->getTypeId() ==
\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE;
$_children = $configProduct->getTypeInstance()-
>getUsedProducts($configProduct);
if ($configurable){
foreach ($_children as $child){
$child_badge = $child->getResource()->getAttribute('mycustom_attribute_code')->getFrontend()->getValue($child);
echo $child_badge;
}
}

Nativescript add class to a button on Tap

I am completely new to Nativescript, I am trying to add class Name dynamically to a gridlayout on tap.
I am not using Angular 2.
How to access the grid layout element and add class name to the same.
All that you need to do is search for the desired element in the UI tree for example by accessing the parent of the Button or by setting an id to the element and using the .getViewById() method of the root of the Page or the Page itself.
Finally in order to set the css class of that View simply set its className property, something like this:
export function onChangeCssClassButtonTap(args) {
var button = args.object as Button;
var parentGridLayout = button.parent as StackLayout;
parentGridLayout.className = "myGridCssClassName";
}
Here are some documentation articles that may be useful to you:
Finding View by its id
Styling in NativeScript

angular ui-grid filter on button click

I'm new in angular. We are using UI-grid for data presentation is is possible to customize filter process. I want to customize it in that way, that filtering is peformmed on button click, not on keydown?
This is idea
$scope.search = function (){
$scope.personCardGrid.useExternalFiltering = false; $scope.grid1Api.core.notifyDataChange(uiGridConstants.dataChange.ALL);
$scope.gridApi.core.refresh() $scope.personCardGrid.useExternalFiltering = true;
$scope.grid1Api.core.notifyDataChange(uiGridConstants.dataChange.ALL);
$scope.gridApi.core.refresh() }
Regards
You need to define your own headerCellTemplate for the column. In the template, add a input text box and a button too. Then, define a function in the controller and call it using the external scope which will filter the records.

sapui5 add runtime new control

how can add new control from controller
// create a simple Input field
var oInput1 = new sap.m.Text('input1');
oInput1.setText("Some Text ");
oInput1.setTooltip("This is a tooltip ");
// attach it to some element in the page
oInput1.placeAt("sample1");
in view I add holder
try to add text from controller but it not display on screen.
var oLayout = this.getView().byId("idholder");
oLayout.addContent(oInput1);
is Run-time add new control is not possible. we have always render control in view and then update it is this good practice we have to follow ?
The placeAt() method is normally only used to place a View or App into the HTML.
If you want to add a UI5 control on your view, you can do it this way from the controller:
this.getView().addContent(oInput1);
But most likely you won't add controls directly to the view, but rather inside a layout or something inside your view. In that case, do it like this:
var oLayout = this.getView().byId("idOfYourSpecificLayoutFrame");
oLayout.addContent(oInput1);

Add an "Add New..." option to a Kendo DropDownList

I'm using a Kendo DropDownListFor which populates from a DB table. I want to add an option at the end that says "Add New..." which takes the user to a Create view for that DB table. Is there a way to do this (preferably in the MVC Helper, not in javascript).
Not possible without JavaScript. If using JavaScript you need to use the change event and see if the value is equal to that last item in the list then navigate the page. Something like this:
function onChangeOfDDl(e){
if(...) { //you condition
window.location.href = "/editRecord/" + this.value()
// this.value() will give you the value for the selected item or the text if no underlying value exists
}
}

Resources