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

Checkbox selection

$
0
0
The checkbox field created with add API method doesn't check the selected values got from the server[when clicked on
Edit button of editor]. Interestingly the checkbox field created using fields initialization option checks the selected values got from the server.

This works:
editor = new $.fn.dataTable.Editor( {
	"ajaxUrl": ".....",
	"domTable": "....",
	"idSrc": "id",
	"fields": [ 
		....
		....
		{
			"label": "User type:",
			"name": "usertype",
			"type": "checkbox",
			"separator": "|",
			"ipOpts": [
				{ "label": "Student", "value": "1" },
				{ "label": "Proctor", "value": "2" }
			]
		}
	], ....
	...
});

Below doesn't show check to selected values:
editor = new $.fn.dataTable.Editor( {
	"ajaxUrl": ".....",
	"domTable": "....",
	"idSrc": "id",
	....
	...
});

editor.on('onInitCreate', function () {
	fnUserScreenFields();
}
editor.on('onInitEdit', function () {
	fnUserScreenFields();
}

function fnUserScreenFields() {
	editor.add({
		"label": "First name:",
		"name": "fname"
	});
	editor.add({
		"label": "Middle name:",
		"name": "mname"
	});
	editor.add({
		"label": "Last name:",
		"name": "lname"
	});
	editor.add({
		"label": "User type:",
		"name": "usertype",
		"type": "checkbox",
		"separator": "|",
		"ipOpts": [
			{ "label": "Student", "value": "1" },
			{ "label": "Proctor", "value": "2" }
		]
	});
	....
	....
}
var table = $('#userlist').dataTable( {
....
});


below is my trimmed json string:
{"sEcho":1,"iTotalRecords":"13","iTotalDisplayRecords":"13","aaData":[{"id":"102674","fname":"xyz",...,"usertype":"1|2"}, ...

Please note in the json string "usertype":"1|2" is the separated list of values to check. The checkboxs are checked [in Edit form of editor] when field is initialized using fields initialization option but when I use the second approach using add method of api the checkboxs are not shown checked in edit form.
http://editor.datatables.net/fields/#checkbox

Any pointers why the second approach doesn't work?

Regards,
Mathew

Viewing all articles
Browse latest Browse all 82590

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>