Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82111

Dependent dropdown example

$
0
0
Here is an example of the use of dependent drop down with country - state example

$('select', editor.node('country')).on('change', function () {
	fnGetStateList(editor.get('country'))
});
editor.on('onInitCreate onInitEdit', function () {
	editor.add({
		"label": "State:",
		"name": "state",
		"type": "select"
	});
	editor.add({
		"label": "Country:",
		"name": "country",
		"type": "select"
	});
	fnGetCountryList();
	fnGetStateList(editor.get('country'));
}
function fnGetCountryList() {
	var countrylist = new Array();
	$.ajax({
		url: '${pageContext.request.contextPath}/admin/getcountrylist.html',
		async: false,
		dataType: 'json',
		success: function (json) {
			for(var i=0; i<json.length; i++){
				countrylist[i] = { "label": json[i].code, "value": json[i].id };
			}
		}
	});
	editor.field('country').update(countrylist);
}
function fnGetStateList(countryId) {
	var statelist = new Array();
	$.ajax({
		url: '${pageContext.request.contextPath}/admin/getstatelist.html?countryId='+countryId,
		async: false,
		dataType: 'json',
		success: function (json) {
			for(var i=0; i<json.length; i++){
				statelist[i] = { "label": json[i].code, "value": json[i].id };
			}
		}
	});
	editor.field('state').update(statelist);
}

sample json string:
[{"id":"2","code":"CA - Canada"},{"id":"1","code":"US - USA"}]

Viewing all articles
Browse latest Browse all 82111

Trending Articles