I have a kendo DropDownList template in which I want to select a specific record by id without using index.
What I want is to select a record with CustomerID
following is my code
$(document).ready(function() {
$("#shopSupplier").kendoDropDownList({
change:shopSupplierSelect,
dataTextField: "ContactName",
dataValueField: "CustomerID",
valueTemplate: 'template',
template: 'template',
dataSource: {
transport: {
read: {
dataType: "json",
cache:false,
url: "<?=base_url()?>/controller/method",
}
}
}
//,index:1 /// **I dont want this**
});
var dropdownlist = $("#shopSupplier").data("kendoDropDownList");
});
If you want to use the id instead of the index you should use:
var dropdownlist = $("#shopSupplier").data("kendoDropDownList");
dropdownlist.select(function(dataItem) {
return dataItem.CustomerID === 4; // Replace it by the ID of the customer
});
making it generic:
var dropdownlist = $("#shopSupplier").data("kendoDropDownList");
function selectByID(id) {
dropdownlist.select(function(dataItem) {
return dataItem.CustomerID === id;
});
}
selectByID(2);
Working example:
$(document).ready(function() {
function shopSupplierSelect() {
alert ("select");
}
$("#shopSupplier").kendoDropDownList({
change:shopSupplierSelect,
dataTextField: "ContactName",
dataValueField: "CustomerID",
valueTemplate: kendo.template($("#template").html()),
template: kendo.template($("#template").html()),
dataSource: {
transport: {
read: function(op) {
var data = [
{ CustomerID: 1, ContactName: "John" },
{ CustomerID: 3, ContactName: "Jack" },
{ CustomerID: 5, ContactName: "Joseph" },
{ CustomerID: 6, ContactName: "Jill" },
{ CustomerID: 2, ContactName: "Jeff" },
{ CustomerID: 4, ContactName: "Jane" }
];
op.success(data);
}
}
}
//,index:1 /// **I dont want this**
});
var dropdownlist = $("#shopSupplier").data("kendoDropDownList");
function selectByID(id) {
dropdownlist.select(function(dataItem) {
return dataItem.CustomerID === id;
});
}
selectByID(2);
});
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.default.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2015.1.429/js/kendo.all.min.js"></script>
<input id="shopSupplier" />
<script id="template" type="text/kendo-templ">
<div><b>#= CustomerID # </b> #: ContactName #</div>
</script>
Kendo UI DropDownList has select method to select specific item. Take a look at this link here
<input id="dropdownlist" />
<script>
$("#dropdownlist").kendoDropDownList({
dataSource: [
{ id: 1, name: "Apples" },
{ id: 2, name: "Oranges" }
],
dataTextField: "name",
dataValueField: "id"
});
var dropdownlist = $("#dropdownlist").data("kendoDropDownList");
// selects item if its text is equal to "test" using predicate function
dropdownlist.select(function(dataItem) {
return dataItem.CustomerID == 12345;
});
</script>
Related
my sql query to fetch state count and state name that give me count and name of the state.
my problem is that i wanted to display multiple markers on google map from database. I need to display the data on click of marker on info window at google map im trying following code.
I'm not able to understand how to add loop in data.addRows.
or please let me know where I'm doing wrong
$sql = "SELECT `state`, COUNT(DISTINCT `sr_no`) AS `stateno`
FROM `Mystate` GROUP BY `state`";
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {
'packages': ['map'],
// Note: you will need to get a mapsApiKey for your project.
// See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
'mapsApiKey': 'API_KEY'
});
google.charts.setOnLoadCallback(drawMap);
function drawMap () {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Address');
data.addColumn('string', 'Location');
data.addColumn('string', 'Marker')
data.addRows([
['Mumbai, Maharashtra', 'India', 'blue' ],
['Pune, Maharashtra', 'India', 'green']
]);
var url = 'https://icons.iconarchive.com/icons/icons-land/vista-map-markers/48/';
var options = {
center: { lat: 20.5937, lng: 78.9629 },
zoomLevel: 5,
showTooltip: true,
showInfoWindow: true,
useMapTypeControl: true,
icons: {
blue: {
normal: url + 'Map-Marker-Ball-Azure-icon.png',
selected: url + 'Map-Marker-Ball-Right-Azure-icon.png'
},
green: {
normal: url + 'Map-Marker-Push-Pin-1-Chartreuse-icon.png',
selected: url + 'Map-Marker-Push-Pin-1-Right-Chartreuse-icon.png'
},
pink: {
normal: url + 'Map-Marker-Ball-Pink-icon.png',
selected: url + 'Map-Marker-Ball-Right-Pink-icon.png'
}
}
};
var map = new google.visualization.Map(document.getElementById('map_div'));
map.draw(data, options);
}
</script>
</head>
<body>
<div id="map_div" style="height: 600px; width: 900px"></div>
</body>
</html>
It is not clear how you hope to select the colour of the marker, nor what you actually do with the stateno from the SQL query. That said, the JSON deata in the following is from one of my old databases and was used to emulate what your query might return. The actual task of processing this recordset and adding the data to the dataTable is done with an Object.keys( json ).forEach loop.
ie:
Object.keys( json ).forEach( key=>{
let obj=json[ key ];
data.addRow([
obj.state, 'India', 'green'
]);
})
The full, working example with a hardcoded valud of green for the marker. I would suggest that this colour could be determined by the stateno data as that is not used but nothing in the above supports that. If that were the case a simple lookup of the stateno number against some sort of matrix of value/colour could be done.
I should possibly warn that running and testing this multiple times could lead to charges being raised against your apikey because of the need for each marker location needing to be geocoded in order to find the location.
<html>
<head>
<script src='https://www.gstatic.com/charts/loader.js'></script>
<script>
const json=[
{
"state":"Andaman and Nicobar Islands",
"stateno":"1"
},
{
"state":"Andhra Pradesh",
"stateno":"104"
},
{
"state":"Arunachal Pradesh",
"stateno":"1"
},
{
"state":"Assam",
"stateno":"15"
},
{
"state":"Bihar",
"stateno":"46"
},
{
"state":"Chandigarh",
"stateno":"1"
},
{
"state":"Chhattisgarh",
"stateno":"12"
},
{
"state":"Delhi",
"stateno":"29"
},
{
"state":"Goa",
"stateno":"3"
},
{
"state":"Gujarat",
"stateno":"63"
},
{
"state":"Haryana",
"stateno":"26"
},
{
"state":"Himachal Pradesh",
"stateno":"1"
},
{
"state":"Jammu and Kashmir",
"stateno":"8"
},
{
"state":"Jharkhand",
"stateno":"23"
},
{
"state":"Karnataka",
"stateno":"65"
},
{
"state":"Kerala",
"stateno":"32"
},
{
"state":"Madhya Pradesh",
"stateno":"53"
},
{
"state":"Maharashtra",
"stateno":"90"
},
{
"state":"Manipur",
"stateno":"1"
},
{
"state":"Meghalaya",
"stateno":"2"
},
{
"state":"Mizoram",
"stateno":"2"
},
{
"state":"Nagaland",
"stateno":"3"
},
{
"state":"Orissa",
"stateno":"22"
},
{
"state":"Pondicherry",
"stateno":"3"
},
{
"state":"Punjab",
"stateno":"34"
},
{
"state":"Rajasthan",
"stateno":"50"
},
{
"state":"Tamil Nadu",
"stateno":"85"
},
{
"state":"Tripura",
"stateno":"3"
},
{
"state":"Uttar Pradesh",
"stateno":"119"
},
{
"state":"West Bengal",
"stateno":"93"
}
];
google.charts.load('current', {
'packages': ['map'],
'mapsApiKey': 'AIzaSy..................04......tA'
});
google.charts.setOnLoadCallback(drawMap);
function drawMap () {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Address');
data.addColumn('string', 'Location');
data.addColumn('string', 'Marker');
/*
data.addRows([
['Mumbai, Maharashtra', 'India', 'blue' ],
['Pune, Maharashtra', 'India', 'green']
]);
*/
Object.keys( json ).forEach( key=>{
let obj=json[ key ];
data.addRow([
obj.state, 'India', 'green'
]);
})
var url = 'https://icons.iconarchive.com/icons/icons-land/vista-map-markers/48/';
var options = {
center: { lat: 20.5937, lng: 78.9629 },
zoomLevel: 5,
showTooltip: true,
showInfoWindow: true,
useMapTypeControl: true,
icons: {
blue: {
normal: url + 'Map-Marker-Ball-Azure-icon.png',
selected: url + 'Map-Marker-Ball-Right-Azure-icon.png'
},
green: {
normal: url + 'Map-Marker-Push-Pin-1-Chartreuse-icon.png',
selected: url + 'Map-Marker-Push-Pin-1-Right-Chartreuse-icon.png'
},
pink: {
normal: url + 'Map-Marker-Ball-Pink-icon.png',
selected: url + 'Map-Marker-Ball-Right-Pink-icon.png'
}
}
};
var map = new google.visualization.Map(document.getElementById('map_div'));
map.draw(data, options);
}
</script>
</head>
<body>
<div id='map_div' style='height: 600px; width: 900px'></div>
</body>
</html>
update
Following on from comments about infoWindows etc I modified the working code I had to perform the lookup and return a different colour icon based upon arbitrary figures ( edit as appropriate if applicable ) and modified the data being added to the dataTable so that the 2nd argument contains the name & count - when the marker is clicked that will be displayed in the tooltip/infoWindow
const matrix={
0:'blue',
30:'green',
75:'pink'
};
const lookup=(i)=>{
let icon=false;
Object.keys( matrix ).forEach( key=>{
if( i > key ) icon=matrix[ key ];
});
return icon
};
Object.keys( json ).forEach( key=>{
let obj=json[ key ];
let icon=lookup( obj.stateno );
data.addRow([
obj.state, `${obj.state} - Count: ${obj.stateno}`, icon
])
});
I am using vue-select. I select province_id then create record success, but when show record, I cannot trigger data selected to select2.
<v-select
v-model="form.province_id"
name="province_id"
:options="provinces"
:reduce="province => province.province_id"
label="name"
:clearable="false"
:searchable="true" />
import vSelect from 'vue-select'
export default {
components: { 'v-select': vSelect },
data () {
const form = {
province_id: ''
}
return {
provinces: []
}
},
}```
Your data declaration is wrong, you need to return form inside the returned object.
import vSelect from 'vue-select'
export default {
components: { 'v-select': vSelect },
data () {
const
return {
provinces: [],
form: {
province_id: undefined
}
}
},
}
Vue.component('v-select', VueSelect.VueSelect);
new Vue({
el: '#app',
data() {
return {
provinces: [
{ name: 'province 1', province_id: 'p_1' },
{ name: 'province 2', province_id: 'p_2' },
{ name: 'province 3', province_id: 'p_3' },
],
form: {
province_id: ''
}
}
},
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<!-- use the latest vue-select release -->
<script src="https://unpkg.com/vue-select#latest"></script>
<link rel="stylesheet" href="https://unpkg.com/vue-select#latest/dist/vue-select.css">
<div id="app">
Selected {{ form.province_id }}
<v-select
v-model="form.province_id"
name="province_id"
:options="provinces"
:reduce="province => province.province_id"
label="name"
:clearable="false"
:searchable="true" />
</div>
I have question regarding series name, How can i set static series name to the element based on the categories in the HighChart.
The expected output will be like this:
As of now I have result on my web app.
Is it possible to change that Series1,Series2,Series3 based on what I want to put on the Series name?
I have here my codes:
categories = [],
series = [];
$.getJSON('ajax/ams_sla_report_chart.php', function(data,name){
data.forEach(function(arr) {
arr.forEach(function(el, i) {
if (i === 0) {
categories.push(el);
} else if (series[i - 1]) {
series[i - 1].data.push(el);
} else {
series.push({
name:['MR','MR_HIT','MR_HIT_PERCENTAGE'],
data: [el]
});
}
});
});
var chart = new Highcharts.Chart({
chart: {
renderTo: 'containers',
type: 'column',
inverted: false
},
legend: {
layout: 'horizontal',
align: 'right',
verticalAlign: 'middle'
},
xAxis: {
categories: categories
},
title: {
text: 'Priority Based on SLA'
},
series:series
});
function showValues() {
$('#alpha-value').html(chart.options.chart.options3d.alpha);
$('#beta-value').html(chart.options.chart.options3d.beta);
$('#depth-value').html(chart.options.chart.options3d.depth);
}
// Activate the sliders
$('#sliders_eng input').on('input change', function () {
chart.options.chart.options3d[this.id] = parseFloat(this.value);
showValues();
chart.redraw(false);
});
showValues();
});
You need to define the series names array outside of the loop and use only one name in the loop:
var seriesNames = ['MR', 'MR_HIT', 'MR_HIT_PERCENTAGE'],
...
data.forEach(function(arr) {
arr.forEach(function(el, i) {
if (i === 0) {
categories.push(el);
} else if (series[i - 1]) {
series[i - 1].data.push(el)
} else {
series.push({
name: seriesNames[i - 1],
data: [el]
});
}
});
});
Live demo: http://jsfiddle.net/BlackLabel/ewauprqh/
I have used this sample to connect to google Api for charts. It works great.
PHP MySQL Google Chart JSON - Complete Example
I am trying to get graphs and charts sample working with PowerBI.
I have sample.html file. I found this sample here:
https://github.com/Microsoft/PowerBI-visuals/wiki/Displaying-visuals-in-a-single-html-page
The file has reference to 1 css file and 2 javscript file on github.
It displays a blank page.
<link href="https://raw.githubusercontent.com/Microsoft/PowerBI-visuals/master/lib/visuals.css" rel="stylesheet">
<script type="text/javascript" src="externals.min.js"></script>
<script type="text/javascript" src="powerbi-visuals.js"></script>
<script type="text/javascript" src="https://raw.githubusercontent.com/Microsoft/PowerBI-visuals/master/lib/powerbi-visuals.js"> </script>
<script type="text/javascript" src="https://raw.githubusercontent.com/Microsoft/PowerBI-visuals/master/lib/powerbi-visuals.min.js"> </script>
<script type="text/javascript" src="https://github.com/Microsoft/PowerBI-visuals/blob/master/lib/powerbi-externals.d.ts"></script>
<style>
.visual {
'background-color' : 'white',
'padding' : '10px',
'margin' : '5px'
}
</style>
</head>
<body>
<script type="text/javascript">
var createDataView = function () {
var DataViewTransform = powerbi.data.DataViewTransform;
var fieldExpr = powerbi.data.SQExprBuilder.fieldExpr({ column: { entity: "table1", name: "country" } });
var categoryValues = ["Australia", "Canada", "France", "Germany", "United Kingdom", "United States"];
var categoryIdentities = categoryValues.map(function (value) {
var expr = powerbi.data.SQExprBuilder.equal(fieldExpr, powerbi.data.SQExprBuilder.text(value));
return powerbi.data.createDataViewScopeIdentity(expr);
});
// Metadata, describes the data columns, and provides the visual with hints
// so it can decide how to best represent the data
var dataViewMetadata = {
columns: [
{
displayName: 'Country',
queryName: 'Country',
type: powerbi.ValueType.fromDescriptor({ text: true })
},
{
displayName: 'Sales Amount (2014)',
isMeasure: true,
format: "$0",
queryName:'sales1',
type: powerbi.ValueType.fromDescriptor({ numeric: true }),
},
{
displayName: 'Sales Amount (2013)',
isMeasure: true,
format: "$0",
queryName:'sales2',
type: powerbi.ValueType.fromDescriptor({ numeric: true })
}
],
};
var columns = [
{
source: dataViewMetadata.columns[1],
// Sales Amount for 2014
values: [742731.43, 162066.43, 283085.78, 300263.49, 376074.57, 814724.34],
},
{
source: dataViewMetadata.columns[2],
// Sales Amount for 2013
values: [742731.43, 162066.43, 283085.78, 300263.49, 376074.57, 814724.34].reverse()
}
];
var dataValues = DataViewTransform.createValueColumns(columns);
var dataView = {
metadata: dataViewMetadata,
categorical: {
categories: [{
source: dataViewMetadata.columns[0],
values: categoryValues,
identity: categoryIdentities,
}],
values: dataValues
}
};
return dataView;
};
function createDefaultStyles(){
var dataColors = new powerbi.visuals.DataColorPalette();
return {
titleText: {
color: { value: 'rgba(51,51,51,1)' }
},
subTitleText: {
color: { value: 'rgba(145,145,145,1)' }
},
colorPalette: {
dataColors: dataColors,
},
labelText: {
color: {
value: 'rgba(51,51,51,1)',
},
fontSize: '11px'
},
isHighContrast: false,
};
}
function createVisual() {
var pluginService = powerbi.visuals.visualPluginFactory.create();
var defaultVisualHostServices = powerbi.visuals.defaultVisualHostServices;
var width = 600;
var height = 400;
var element = $('.visual');
element.height(height).width(width);
// Get a plugin
var visual = pluginService.getPlugin('columnChart').create();
powerbi.visuals.DefaultVisualHostServices.initialize();
visual.init({
// empty DOM element the visual should attach to.
element: element,
// host services
host: defaultVisualHostServices,
style: createDefaultStyles(),
viewport: {
height:height,
width: width
},
settings: { slicingEnabled: true },
interactivity: { isInteractiveLegend: false, selection: false },
animation: { transitionImmediate: true }
});
// Call update to draw the visual with some data
visual.update({
dataViews: [createDataView()] ,
viewport: {
height: height,
width: width
},
duration: 0
});
}
createVisual();
</script>
<div class="visual"></div>
</body>
</html>
The reference files are located at this location:
<script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/externals.min.js"> </script>
<script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/powerbi-visuals.js" ></script>
<script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/PowerBIVisualsPlayground.js"></script>
This is the full working script:
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link href="https://raw.githubusercontent.com/Microsoft/PowerBI-visuals/master/lib/visuals.css" rel="stylesheet">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/externals.min.js"> </script>
<script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/powerbi-visuals.js" ></script>
<script type="text/javascript" src="http://microsoft.github.io/PowerBI-visuals/playground/PowerBIVisualsPlayground.js"></script>
<style>
.visual {
'background-color' : 'white',
'padding' : '10px',
'margin' : '5px'
}
</style>
</head>
<body>
<h1> hello </h1>
<div class="visual"></div>
<script type="text/javascript">
var createDataView = function () {
var DataViewTransform = powerbi.data.DataViewTransform;
var fieldExpr = powerbi.data.SQExprBuilder.fieldExpr({ column: { entity: "table1", name: "country" } });
var categoryValues = ["Australia", "Canada", "France", "Germany", "United Kingdom", "United States"];
var categoryIdentities = categoryValues.map(function (value) {
var expr = powerbi.data.SQExprBuilder.equal(fieldExpr, powerbi.data.SQExprBuilder.text(value));
return powerbi.data.createDataViewScopeIdentity(expr);
});
// Metadata, describes the data columns, and provides the visual with hints
// so it can decide how to best represent the data
var dataViewMetadata = {
columns: [
{
displayName: 'Country',
queryName: 'Country',
type: powerbi.ValueType.fromDescriptor({ text: true })
},
{
displayName: 'Sales Amount (2014)',
isMeasure: true,
format: "$0",
queryName:'sales1',
type: powerbi.ValueType.fromDescriptor({ numeric: true }),
},
{
displayName: 'Sales Amount (2013)',
isMeasure: true,
format: "$0",
queryName:'sales2',
type: powerbi.ValueType.fromDescriptor({ numeric: true })
}
],
};
var columns = [
{
source: dataViewMetadata.columns[1],
// Sales Amount for 2014
values: [742731.43, 162066.43, 283085.78, 300263.49, 376074.57, 814724.34],
},
{
source: dataViewMetadata.columns[2],
// Sales Amount for 2013
values: [742731.43, 162066.43, 283085.78, 300263.49, 376074.57, 814724.34].reverse()
}
];
var dataValues = DataViewTransform.createValueColumns(columns);
var dataView = {
metadata: dataViewMetadata,
categorical: {
categories: [{
source: dataViewMetadata.columns[0],
values: categoryValues,
identity: categoryIdentities,
}],
values: dataValues
}
};
return dataView;
};
function createDefaultStyles(){
var dataColors = new powerbi.visuals.DataColorPalette();
return {
titleText: {
color: { value: 'rgba(51,51,51,1)' }
},
subTitleText: {
color: { value: 'rgba(145,145,145,1)' }
},
colorPalette: {
dataColors: dataColors,
},
labelText: {
color: {
value: 'rgba(51,51,51,1)',
},
fontSize: '11px'
},
isHighContrast: false,
};
}
function createVisual() {
var pluginService = powerbi.visuals.visualPluginFactory.create();
var defaultVisualHostServices = powerbi.visuals.defaultVisualHostServices;
var width = 600;
var height = 400;
var element = $('.visual');
element.height(height).width(width);
// Get a plugin
var visual = pluginService.getPlugin('columnChart').create();
powerbi.visuals.DefaultVisualHostServices.initialize();
visual.init({
// empty DOM element the visual should attach to.
element: element,
// host services
host: defaultVisualHostServices,
style: createDefaultStyles(),
viewport: {
height:height,
width: width
},
settings: { slicingEnabled: true },
interactivity: { isInteractiveLegend: false, selection: false },
animation: { transitionImmediate: true }
});
// Call update to draw the visual with some data
visual.update({
dataViews: [createDataView()] ,
viewport: {
height: height,
width: width
},
duration: 0
});
}
createVisual();
</script>
</body>
</html>
I got problem with displaying in x-editable html img generated in the formatSelection of the select2.
Select2 dropdown displays correctly images, but x-editable doesn't.
I have:
<a href="#" class="editable-select" data-pk="10" data-url="/my_url/1" data-name="my_data_id" data-value="1" data-type="select2"/></a>
<script>
function format(state) {
var result = "";
if(state.id){
result = '<img src="/path_to_img/et'+state.id+'.png"/>';
}
return result;
}
$('.editable-select').editable({
source: [
{id: '1', text: 'option_1'},
{id: '2', text: 'option_2'},
{id: '3', text: 'option_3'},
],
select2: {
formatResult: format,
formatSelection: format,
escapeMarkup: function (m) {return m; }
}
});
</script>
As a result I have editable which displays
<img src="/path_to_img/et1.png"/>
as pure text instead of displaying image et1.png.
The reason for this is x-editable which assigns whatever text (pure or formatted) it gets from select2 formatSelection to editable component as text through $(element).text(text).
If formatted text were assigned through $(element).html(text) image would have been displayed instead of text.
What would be the best way around this to make x-editable assign correctly html formatted content to element text?
An example with Awesome icons font (can be easily formated to <img> tag instead of <i>)
var icons = [];
$.each({
"compass" : "icon-compass",
"eur" : "icon-eur",
"dollar" : "icon-dollar",
"yen" : "icon-yen",
"won" : "icon-won",
"file-text" : "icon-file-text",
"sort-by-attributes-alt" : "icon-sort-by-attributes-alt",
}, function (k, v) {
icons.push({
id: k,
style: v
});
});
function format(icon) {
if (!icon.id) return icon.style;
return "<i class='icon-" + icon.id + "'></i> " + icon.style;
}
$('#awsome_icons_select').editable({
inputclass: 'form-control input-medium select2',
select2: {
allowClear: true,
formatResult: format,
formatSelection: format,
escapeMarkup: function (m) {
return m;
}
},
source: icons,
display: function (value) {
if (!value) {
$(this).empty();
return;
}
var html = "<i class='icon-" + value + "'></i> ";
$(this).html(html);
}
});
This should do the trick for image:
var countries= [];
$.each({
"US" : "USA",
"RU" : "Russia",
"DK" : "Denmark",
"FR" : "France",
"PL" : "Poland",
"DE" : "Germany",
"GB" : "Great Britain",
}, function (k, v) {
countries.push({
id: k,
state: v
});
});
function format(country) {
if (!country.id) return country.state;
return "<img src='path_to_images/" + country.id + ".png' /> " + country.state;
}
$('#countries_select').editable({
inputclass: 'form-control input-medium select2',
select2: {
allowClear: true,
formatResult: format,
formatSelection: format,
escapeMarkup: function (m) {
return m;
}
},
source: countries,
display: function (value) {
if (!value) {
$(this).empty();
return;
}
var html = "<img src='path_to_images/" + value + ".png' /> ";
$(this).html(html);
}
});