Before few days i get one static json to implement in my code from jsfiddle and did some changes to create dynamic json from it. jsfiddle from which i got code
Now My code is working.but i want some changes in it.Below is my current code and image that data i got from mysql with json.
$(document).ready(function() {
var data = [];
$.ajax({
url: "<?php echo base_url('responsible/get_pay_slips'); ?>",
datatype: 'json',
success: function(response) {
response = $.parseJSON(response);
x = 0;
$.each(response, function(i, value) {
console.log(value.PAY_YEAR, value.PAY_MONTH);
var data1 = [];
data[x++] = {
text: value.PAY_YEAR,
data: {},
children: [{
text: value.PAY_MONTH,
data: {
price: 0.1,
quantity: 20
}
}, ],
'state': {
'opened': false
}
};
});
console.log(data);
// load jstree
$("div#jstree").jstree({
plugins: ["table", "dnd", "contextmenu", "sort"],
core: {
data: data
},
// configure tree table
table: {
columns: [{
width: 500,
header: "YEAR"
},
{
width: 300,
value: "ACTION",
header: "ACTION",
format: function(v) {
if (v) {
return 'Print | Save'
}
}
},
],
resizable: true,
draggable: true,
contextmenu: true,
}
});
}
});
});
Current flow of data:
flow that i actully want:
So, How can we create PAY_MONTH
of same PAY_YEAR
in single tree.
i want only one parent PAY_YEAR
and within it his all childerns PAY_MONTH
.
I am using codeigniter.
My model:
public function json_get_slips()
{
$empid ='34';
$where = "where EMPLOYEE_ID='".$empid."' ";
$query = $this->db->query("select PAY_MONTH,PAY_YEAR from india_salary_slip_details ".$where." group by pay_month order by pay_year");
return $query->result_array();
}
My controller:
public function get_pay_slips()
{
$data = array();
$data=$this->pay_slips->json_get_slips();
echo json_encode($data);
}
I dont know much about jquery and here i want to create dynamic data with it.I am hopeless.please help me with the same.