Sending and getting an Array using fnServerParams
Sending and getting an Array using fnServerParams
SpreADX
Posts: 8Questions: 0Answers: 0
I am having problems sending and getting data from an array using fnServerParams. Can some one please help?
Thanks my javascript code
[code]
function generateDataTable(subject, checkboxes) {
var oTable = $('#datatable1').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": base_url() + '/' + 'ccreateexam/getQuestions',
"fnServerParams": function(aoData) {
aoData.push({"name": "subject", "value": subject});
aoData.push({"name": "checkboxes[]", "value": checkboxes});
},
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ": 20,
"oLanguage": {
//"sProcessing": ""
},
"fnInitComplete": function() {
oTable.fnAdjustColumnSizing();
},
'fnServerData': function(sSource, aoData, fnCallback)
{
// alert(sSource);
$.ajax
({
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': fnCallback
});
}
});
}
[/code]
And in my controller
[code]
public function getQuestions() {
$subject = $this->input->post('subject');
$checkboxes = $this->input->post('checkboxes');
echo $this->mcreateexam->getQuestionsForSubjectLessons2($subject, $checkboxes);
}
[/code]
Thanks
Thanks my javascript code
[code]
function generateDataTable(subject, checkboxes) {
var oTable = $('#datatable1').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": base_url() + '/' + 'ccreateexam/getQuestions',
"fnServerParams": function(aoData) {
aoData.push({"name": "subject", "value": subject});
aoData.push({"name": "checkboxes[]", "value": checkboxes});
},
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ": 20,
"oLanguage": {
//"sProcessing": ""
},
"fnInitComplete": function() {
oTable.fnAdjustColumnSizing();
},
'fnServerData': function(sSource, aoData, fnCallback)
{
// alert(sSource);
$.ajax
({
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': fnCallback
});
}
});
}
[/code]
And in my controller
[code]
public function getQuestions() {
$subject = $this->input->post('subject');
$checkboxes = $this->input->post('checkboxes');
echo $this->mcreateexam->getQuestionsForSubjectLessons2($subject, $checkboxes);
}
[/code]
Thanks
This discussion has been closed.
Replies
Allan
javascript
[code]
function generateDataTable(subject, checkboxesData) {
var oTable = $('#datatable1').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": base_url() + '/' + 'ccreateexam/getQuestions',
"fnServerParams": function(aoData) {
aoData.push({"name": "subject", "value": subject});
aoData.push({"name": "lessonsCount", "value": checkboxesData[0]});
for(var i = 0; i < checkboxesData[0]; i++){
aoData.push({"name": "selectedLessons[]", "value": checkboxesData[1][i]});
}
},
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ": 20,
"fnInitComplete": function() {
oTable.fnAdjustColumnSizing();
},
'fnServerData': function(sSource, aoData, fnCallback)
{
$.ajax
({
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': fnCallback
});
}
});
}
[/code]
controller
[code]
public function getQuestions() {
$subject = $this->input->post('subject');
$lessonsCount = $this->input->post('lessonsCount');
$selectedLessons = $this->input->post('selectedLessons');
if (!empty($subject)) {
echo $this->mcreateexam->getQuestionsForSubjectLessons($subject, $selectedLessons, $lessonsCount);
} else {
echo $this->mcreateexam->getQuestionsForAllSubjectsLessons($selectedLessons, $lessonsCount);
}
}
[/code]
Now we are stuck trying to add a checkbox for every row in the datatable in a new column with a paramatrized name or id. Now, we're adding the checkbox with specific id, but we need each checkbox to have a diferent name or id, so we can recover the checked status using javascript. Do you have any idea to help us? We thank you very much for your work and your time. Thanks.
[code]
{
mData: null,
mRender: function ( data, type, row ) {
return '';
}
}
[/code]
Assuming you have an `id` property in the row source object. Change to whatever you do have.
Allan
[code]
$(document).ready(function() {
$('#createExamButton').click(function() {
var oTable = $('#datatable1').dataTable();
var checkedQuestions = [];
$("input:checked", oTable.fnGetNodes()).each(function(){
var elemnt = this;
checkedQuestions.push(elemnt.id);
});
alert(checkedQuestions);
});
});
[/code]