Related
I have this code below, i want to have select options for column 'WhoAttend' and 'Description', so i implemented some dropdownlist using render to do this and was unfortunate until today. Any help will be highly appreciated, thanks mates and have seen the documentation on DataTable.net but i could not get this right. Surely i am missing some little bit of logic somehow and need some guidance to this logic below.
<h2>EventManagement List</h2>
<table id="EventsManagementsTable" class="cell-border" style="width:100%">
<thead>
<tr>
<th>TrainingType</th>
<th>TrainingDescription</th>
<th>Price</th>
<th>Venue</th>
<th>Facilitator</th>
<th>WhoAttend</th>
<th>RSVP</th>
</tr>
</thead>
</table>
#section scripts{
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$("#EventsManagementsTable").DataTable({
"columns": [
{
"data": "WhoAttend",
"name": "WhoAttend",
"render": function (value) {
return $("<select/>")
.addClass("form-control")
.attr("name", "WhoAttend")
.append($("<option/>").text("Engineers"))
.append($("<option/>").text("Inspectors"))
.append($("<option/>").text("Technicians"))
.val(value)
.html();
}
}
],
"serverSide": "true",
"order": [0, "asc"],
"processing": "true",
"paginng": true,
"ordering":true,
"language": {
"processing": "processing...... please wait"
},
"ajax": {
"url": "/Dashboard/GetData",
"type": "POST",
"datatype": "JSON"
},
"columns": [
{ "data": "TrainingType", "name": "TrainingType", "autoWidth": true },
{ "data": "TrainingDescription", "name": "TrainingDescription", "autoWidth": true },
{ "data": "Price", "name": "Price", "autoWidth": true },
{ "data": "Venue", "name": "Venue", "autoWidth": true },
{ "data": "Facilitator", "name": "Facilitator", "autoWidth": true },
{ "data": "WhoAttend", "name": "WhoAttend", "autoWidth": true },
{ "data": "RSVP", "name": "RSVP", "autoWidth": true },
]
});
});
</script>
// Remodified code
$(document).ready(function () {
$("#EventsManagementsTable").DataTable({
/*"columns": [
{
"data": "WhoAttend",
"name": "WhoAttend",
"render": function (value) {
return $("<select/>")
.addClass("form-control")
.attr("name", "WhoAttend")
.append($("<option/>").text("Engineers"))
.append($("<option/>").text("Inspectors"))
.append($("<option/>").text("Technicians"))
.val(value)
.html();
}
}
],
*/
"columns": [
{ "data": "TrainingType", "name": "trainingType", "autoWidth": true },
{ "data": "TrainingDescription", "name": "trainingDescription", "autoWidth": true },
{ "data": "Price", "name": "price", "autoWidth": true },
{ "data": "Venue", "name": "venue", "autoWidth": true },
{ "data": "Facilitator", "name": "facilitator", "autoWidth": true },
{ "data": "WhoAttend", "name": "whoAttend", "autoWidth": true },
{ "data": "RSVP", "name": "rsvp", "autoWidth": true },
],
"serverSide": "true",
"order": [0, "asc"],
"processing": "true",
"paging": true,
"ordering":true,
"language": {
"processing": "processing...... please wait"
},
"ajax": {
"url": "/Dashboard/GetData",
"type": "POST",
"datatype": "JSON"
}
});
});
</script>
Without knowing more about the problem I would give you a few things to try:
You are defining "columns" definition twice. Once above and once below. It is likely to take the value of the second one and overwrite the first one you define up top so put the top one in the rest at the bottom an decide if you are going to override it.
Simple thing is paging is misspelled maybe:
"paginng": true,
Change to "paging"
Validate the specified values for data such as "TrainingType" are the same as in the data set returned in the JSON from the server? For example is it like this:
{ "trainingType": {value}, "trainingDescription": {value}, "price": {value}, "venue":{value}, "facilitator": {value}, "whoAttend": {value}, "rsvp": {value} }
I only ask because often JSON data is returned in camel case so it would be good to check if the data table code is case sensitive?
Edit: Ah, I see what is going on this is that one thing where it doesn't like to make selects. I don't remember what the rationale for it was but anyways here is some code that will work.
$(document).ready(function () {
$("#EventsManagementsTable").DataTable({
"serverSide": "true",
"order": [0, "asc"],
"processing": "true",
"paging": true,
"ordering":true,
"language": {
"processing": "processing...... please wait"
},
"ajax": {
"url": "/Dashboard/GetData",
"type": "GET",
"datatype": "JSON"
},
"columns": [
{ "data": "trainingType", "name": "TrainingType", "autoWidth": true },
{ "data": "trainingDescription", "name": "TrainingDescription", "autoWidth": true },
{ "data": "price", "name": "Price", "autoWidth": true },
{ "data": "venue", "name": "Venue", "autoWidth": true },
{ "data": "facilitator", "name": "Facilitator", "autoWidth": true },
{
"data": "whoAttend",
"name": "WhoAttend",
"render": function (value) {
var sel = $('<select />')
.addClass("form-control")
.attr("name", "WhoAttend")
.append($("<option/>", { text: "Engineers", value: "Engineers" }))
.append($("<option/>", { text: "Inspectors", value: "Inspectors" }))
.append($("<option/>", { text: "Technicians", value: "Technicians" }))[0];
$(sel.options).each(function() {
if(this.value === value) {
$(this).attr("selected",true);
}
});
return sel.outerHTML;
},
"autoWidth": true
},
{ "data": "rsvp", "name": "RSVP", "autoWidth": true }
]
});
});
P.S. Don't hold the [0] part of that one line against me. It works. ;-) Maybe you could tell me why it works this way. I remember something like this happening before and someone told me why the val() doesn't select and why the select creation messes up and a more proper way to do it but I don't remember what it all was now. Anyways the code above should surely work now for sure.
I'm currently writing swagger 3.0 documentation and using reDoc to render as nice UI for it. I have a few scenarios in my documentation where based on a previous properties enum I would want to display different schema object properties. Sadly I cant seam to figure out how to wire this together properly in my documentation. So far I have the following test endpoint:
{
"post": {
"operationId" : "test",
"summary": "test",
"description": "test",
"tags": [ "test" ],
"consumes": "application/json",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "./schemas/test1.json"
},
{
"$ref": "./schemas/test2.json"
}
],
"discriminator": {
"propertyName": "pet_type",
"mapping": {
"click": "./schemas/test1.json",
"open": "./schemas/test2.json"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
}
The test1.json looks like this:
{
"Cat": {
"type": "object",
"properties": {
"pet_type": {
"type": "string"
},
"hunts": {
"type": "boolean"
},
"age": {
"type": "integer"
}
},
"discriminator": {
"propertyName": "pet_type"
}
}
}
And the test2.json like this:
{
"Dog": {
"type": "object",
"properties": {
"pet_type": {
"type": "string"
},
"bark": {
"type": "boolean"
},
"breed": {
"type": "string",
"enum": [
"Dingo",
"Husky",
"Retriever",
"Shepherd"
]
}
},
"discriminator": {
"propertyName": "pet_type"
}
}
}
The desired out come would be to toggle between the two "test" jsons based on an enum (the drop down seen in the reDoc sample). What am I missing to get this result?
You can see an example of the discriminator result here under the feature section (the first gif)
After more digging I was able to figure out the issue... my structure for the most part.
On my index.json file I updated my components section to point at my components folder containing the schema as such:
"components": {
"$ref": "./components/test.json"
},
The test.json looks like the following:
{
"schemas": {
"Refinance": {
"description": "A representation of a cat",
"allOf": [
{
"$ref": "#/schemas/Pet"
},
{
"type": "object",
"properties": {
"huntingSkill": {
"type": "string",
"description": "The measured skill for hunting",
"default": "lazy",
"enum": [
"clueless",
"lazy",
"adventurous",
"aggressive"
]
}
},
"required": [
"huntingSkill"
]
}
]
},
"Purchase": {
"description": "A representation of a dog",
"allOf": [
{
"$ref": "#/schemas/Pet"
},
{
"type": "object",
"properties": {
"packSize": {
"type": "integer",
"format": "int32",
"description": "The size of the pack the dog is from",
"default": 1,
"minimum": 1
},
"foobar": {
"type": "string",
"description": "some ol bullshit"
}
},
"required": [
"packSize"
]
}
]
},
"Pet": {
"type": "object",
"discriminator": {
"propertyName": "petType"
},
"properties": {
"petType": {
"description": "Type of a pet",
"type": "string"
}
},
"xml": {
"name": "Pet"
}
}
}
}
And finally the schema for the endpoint gets referenced as follows:
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "../../index.json#/components/schemas/Pet"
}
}
}
},
I used automatical OData connection with SAP Web IDE. Unfortunately, Data don't connect and Layout Editor says that Data Set "not defined". I have tried to connect by coding, for example <Table items={/Stats}>, but it doesn't work either. When I use project template (Master-Detail or Worklist), there are no problems with connection and Data is automatically connecting, but when I want to make my project and make a connection, there are always some problems.
Component.js
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/Device",
"Statusverwaltung/model/models"
], function(UIComponent, Device, models) {
"use strict";
return UIComponent.extend("Statusverwaltung.Component", {
metadata: {
manifest: "json"
},
config : {
"resourceBundle" : "i18n/i18n.properties",
"titleResource" : "SHELL_TITLE",
"serviceConfig" : {
name: "UI5STAT1_SRV",
serviceUrl: "/sap/opu/odata/kernc/UI5STAT1_SRV/"
}
},
/**
* The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
* #public
* #override
*/
init: function() {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
// set the device model
this.setModel(models.createDeviceModel(), "device");
}
});
});
Manifest.json
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "Statusverwaltung",
"type": "application",
"i18n": "i18n/i18n.properties",
"applicationVersion": {
"version": "1.0.0"
},
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"sourceTemplate": {
"id": "servicecatalog.connectivityComponent",
"version": "0.0.0"
},
"dataSources": {
"UI5STAT1_SRV": {
"uri": "/sap/opu/odata/kernc/UI5STAT1_SRV/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "webapp/localService/UI5STAT1_SRV/metadata.xml"
}
}
}
},
"sap.ui": {
"_version": "1.1.0",
"technology": "UI5",
"icons": {
"icon": "",
"favIcon": "",
"phone": "",
"phone#2": "",
"tablet": "",
"tablet#2": ""
},
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
},
"supportedThemes": ["sap_hcb", "sap_bluecrystal"]
},
"sap.ui5": {
"_version": "1.1.0",
"rootView": {
"viewName": "Statusverwaltung.view.View",
"type": "XML"
},
"dependencies": {
"minUI5Version": "1.30.0",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.ui.layout": {}
}
},
"contentDensities": {
"compact": true,
"cozy": true
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "Statusverwaltung.i18n.i18n"
}
}
},
"resources": {
"css": [{
"uri": "css/style.css"
}]
},
"routing": {
"targets": {
"View": {
"viewType": "XML",
"transition": "slide",
"clearAggregation": true,
"viewName": "View",
"viewId": "View"
}
}
}
}
}
neo-app.json
{
"welcomeFile": "/webapp/index.html",
"routes": [
{
"path": "/resources",
"target": {
"type": "service",
"name": "sapui5",
"entryPath": "/resources"
},
"description": "SAPUI5 Resources"
},
{
"path": "/test-resources",
"target": {
"type": "service",
"name": "sapui5",
"entryPath": "/test-resources"
},
"description": "SAPUI5 Test Resources"
},
{
"path": "/sap/opu/odata",
"target": {
"type": "destination",
"name": "v01",
"entryPath": "/sap/opu/odata"
},
"description": "V01 description"
}
],
"sendWelcomeFileRedirect": true
}
.project.json
{
"projectType": [
"sap.watt.uitools.ide.fiori",
"sap.watt.uitools.ide.web",
"sap.watt.saptoolsets.fiori.project.ui5template.smartProject",
"sap.watt.saptoolsets.fiori.project.uiadaptation"
],
"build": {
"targetFolder": "dist",
"sourceFolder": "webapp"
},
"generation": [
{
"templateId": "ui5template.basicSAPUI5ApplicationProject",
"templateVersion": "1.32.0",
"dateTimeStamp": "Mon, 17 Oct 2016 08:28:52 GMT"
},
{
"templateId": "servicecatalog.connectivityComponent",
"templateVersion": "0.0.0",
"dateTimeStamp": "Mon, 17 Oct 2016 10:10:52 GMT"
},
{
"templateId": "uiadaptation.changespreviewjs",
"templateVersion": "0.0.0",
"dateTimeStamp": "Tue, 18 Oct 2016 08:08:06 GMT"
}
],
"translation": {
"translationDomain": "",
"supportedLanguages": "en,fr,de",
"defaultLanguage": "en",
"defaultI18NPropertyFile": "i18n.properties",
"resourceModelName": "i18n"
},
"basevalidator": {
"services": {
"xml": "fioriXmlAnalysis",
"js": "fioriJsValidator"
}
},
"codeCheckingTriggers": {
"notifyBeforePush": true,
"notifyBeforePushLevel": "Error",
"blockPush": false,
"blockPushLevel": "Error"
},
"mockpreview": {
"mockUri": "/sap/opu/odata/kernc/UI5STAT1_SRV/",
"metadataFilePath": "webapp/localService/UI5STAT1_SRV/metadata.xml",
"loadJSONFiles": false,
"loadCustomRequests": false,
"mockRequestsFilePath": ""
}
}
It seems like you are never instantiating a model.
You can do that in the manifest.json
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "Statusverwaltung.i18n.i18n"
}
},
"": {
"dataSource":"UI5STAT1_SRV"
}
},
"" defines the default model so you can use Bindingpaths like {/Stats}.
I am trying to hide Feature of a layer from jason where I define the feature by category. I tried Jonatas Walker method but my code is different not working http://jsfiddle.net/jonataswalker/z10de36z/ but my code is different so not working
Below is my json
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "Missing Person",
"src": "resources/icon.png",
"category": "cat1"
},
"geometry": {
"type": "Point",
"coordinates": [-0.45755, 51.507222]
}
},
{
"type": "Feature",
"properties": {
"name": "Wanted",
"src": "resources/icon.png",
"category": "cat1"
},
"geometry": {
"type": "Point",
"coordinates": [-0.12755, 52.507222]
}
},
{
"type": "Feature",
"properties": {
"name": "Missing 1",
"src": "resources/Blue_pointer.png",
"category": "cat2"
},
"geometry": {
"type": "Point",
"coordinates": [-1.12755, 52.507222]
}
},
{
"type": "Feature",
"properties": {
"name": "Wanted 3",
"src": "resources/icon.png",
"category": "cat1"
},
"geometry": {
"type": "Point",
"coordinates": [-2.12755, 53.507222]
}
},
{
"type": "Feature",
"properties": {
"name": "Wanted 7",
"src": "resources/icon.png",
"category": "cat1"
},
"geometry": {
"type": "Point",
"coordinates": [-0.1287, 53.507222]
}
},
{
"type": "Feature",
"properties": {
"name": "Wanted 9",
"src": "resources/Blue_pointer.png",
"category": "cat2"
},
"geometry": {
"type": "Point",
"coordinates": [-3.12755, 50.907222]
}
},
{
"type": "Feature",
"properties": {
"name": "Missing 8",
"src": "resources/Blue_pointer.png",
"category": "cat2"
},
"geometry": {
"type": "Point",
"coordinates": [-3.12755, 51.907222]
}
},
{
"type": "Feature",
"properties": {
"name": "Missing 18",
"src": "resources/Blue_pointer.png",
"category": "cat2"
},
"geometry": {
"type": "Point",
"coordinates": [-4.12755, 51.907222]
}
}
]
}
Openlayer code
var styleFunction1 = function(feature) {
var styles = {
'Point': [
new ol.style.Style({
image: new ol.style.Icon({
src: feature.get('src'),
anchor: [0.5, 1]
})
})],
'LineString': [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'gray',
width: 5
})
})]
};
return styles[feature.getGeometry().getType()];
};
vector = new ol.layer.Vector({
source: new ol.source.Vector({
projection : 'EPSG:4326',
format: new ol.format.GeoJSON(),
url: 'resources/multipoint.geojson'
}),
style: styleFunction1
});
map = new ol.Map({
target: target,
layers: [bingMapsRoad,myPetrolPlan,vector],
view: new ol.View({
center: ol.proj.transform([-0.12755, 51.507222], 'EPSG:4326', 'EPSG:3857'),
loadTilesWhileAnimating: true,
loadTilesWhileInteracting: true,
zoom: 6
}),
controls: ol.control.defaults({ attribution: false }),
loadTilesWhileInteracting: true
});
To Hide I am trying something like
hideVectorLayer: function () {
var abc = ConnectWebMap;
var featureCount = vector.getSource().getFeatures();
var featureCat = feature.get('category');
console.log(featureCat);
featureCount.forEach(function(feature) {
if(feature){
if(featureCat == 'cat1'){
console.log('a');
}
}
});
}
You can remove from the VectorSource using removeFeature method
you can make another layer ( a temporary one ) where you copy the features from the desired category and display it while setting the visibility of your main layer to false:
var tmp=new ol.layer.vector({ source : new ol.source.Vector()});
hideVectorLayer: function () {
var abc = ConnectWebMap;
var featureCount = vector.getSource().getFeatures();
var featureCat = feature.get('category');
console.log(featureCat);
featureCount.forEach(function(feature) {
if(feature){
if(featureCat == 'cat1'){
tmp.getSource().getFeatures().push(feature);
}
}
});
tmp.setStyle(vector.getStyle()); // set the same style to the tmp layer
map.addLayer(tmp);// add it to the map
vector.setVisible(false); // set the vector layer visibility to false
}
I'm using Elasticsearch and create an index with the following information for mapping and settings. The problem I have is that my field geography.locality which should use the 'name_analyser' doesn't seem to use it.
{
"index": "programs",
"body": {
"settings": {
"number_of_shards": 5,
"analysis": {
"filter": {
"elision": {
"type": "elision",
"articles": [
"l",
"m",
"t",
"qu",
"n",
"s",
"j",
"d"
]
},
"multi_words": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 10
},
"name_filter": {
"type": "edgeNGram",
"max_gram": 100,
"min_gram": 2
}
},
"tokenizer": {
"name_tokenizer": {
"type": "edgeNGram",
"max_gram": 100,
"min_gram": 2
}
},
"analyser": {
"name_analyser": { // <-- analyser I want to use on geography.locality
"tokenizer": "whitespace",
"type": "custom",
"filter": [
"lowercase",
"multi_words",
"name_filter",
"asciifolding"
]
},
"french": {
"tokenizer": "letter",
"filter": [
"asciifolding",
"lowercase",
"elision",
"stop"
]
},
"city_name": {
"type": "custom",
"tokenizer": "letter",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"program": {
"properties": {
"nid": {
"type": "integer",
"index": "not_analyzed"
},
"title": {
"type": "string"
},
"language": {
"type": "string",
"index": "not_analyzed"
},
"regulation": {
"type": "integer"
},
"sales_state": {
"type": "integer"
},
"enabled_dwell": {
"type": "boolean"
},
"enabled_invest": {
"type": "boolean"
},
"delivery_date": {
"type": "date"
},
"address": {
"properties": {
"country": {
"type": "string",
"index": "not_analyzed"
},
"locality": {
"type": "string",
"analyser": "name_analyser"
},
"postal_code": {
"type": "integer"
},
"thoroughfare": {
"type": "string",
"index": "not_analyzed"
},
"premise": {
"type": "string",
"index": "not_analyzed"
}
}
},
"location": {
"type": "geo_point"
},
"geography": {
"properties": {
"locality": {
"type": "string",
"analyser": "name_analyser" // ... here :-/
},
"department": {
"type": "string",
"index": "not_analyzed"
},
"region": {
"type": "string",
"index": "not_analyzed"
}
}
},
"lots": {
"type": "nested",
"include_in_all": false,
"properties": {
"lot_type": {
"type": "integer"
},
"rooms": {
"type": "integer"
},
"price_vat_inc": {
"type": "integer"
},
"price_reduced_vat_inc": {
"type": "integer"
},
"price_vat_ex": {
"type": "integer"
}
}
}
}
}
}
}
}
Here's the output given by ES for the mapping registered for this index.
{
"program": {
"properties": {
"address": {
"properties": {
"country": {
"index": "not_analyzed",
"type": "string"
},
"premise": {
"index": "not_analyzed",
"type": "string"
},
"locality": {
"type": "string"
},
"postal_code": {
"type": "integer"
},
"thoroughfare": {
"index": "not_analyzed",
"type": "string"
}
}
},
"sales_state": {
"type": "integer"
},
"nid": {
"type": "integer"
},
"language": {
"index": "not_analyzed",
"type": "string"
},
"title": {
"type": "string"
},
"enabled_invest": {
"type": "boolean"
},
"geo_point": {
"type": "string"
},
"lots": {
"include_in_all": false,
"type": "nested",
"properties": {
"rooms": {
"include_in_all": false,
"type": "integer"
},
"price_vat_inc": {
"include_in_all": false,
"type": "integer"
},
"price_vat_ex": {
"include_in_all": false,
"type": "integer"
},
"lot_type": {
"include_in_all": false,
"type": "integer"
},
"price_reduced_vat_inc": {
"include_in_all": false,
"type": "integer"
}
}
},
"enabled_dwell": {
"type": "boolean"
},
"delivery_date": {
"format": "dateOptionalTime",
"type": "date"
},
"regulation": {
"type": "integer"
},
"geography": {
"properties": {
"locality": {
"type": "string" // name_analyser should show up here right?????
},
"department": {
"index": "not_analyzed",
"type": "string"
},
"region": {
"index": "not_analyzed",
"type": "string"
}
}
},
"location": {
"type": "geo_point"
}
}
}
}
Does anybody knows what I am doing wrong? I'm kind of lost about this.
You have a typo :-), actually two:
"locality": {
"type": "string",
"analyser": "name_analyser"
},
in both address and geography. It should be analyzer not analyser (with an s).
Also, the same here:
"analyser": {
"name_analyser": {
"tokenizer": "whitespace",
...
I am guessing that the index exists and you are trying to update the settings with a new analyser. This is not permitted on a live index.
Do you have any errors when you submit the updated settings?
Have a look at this thread - Change settings and mappings on existing index in Elasticsearch
and here http://www.elastic.co/guide/en/elasticsearch/reference/1.x/indices-update-settings.html#update-settings-analysis