-1

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: Current flow of data flow that i actully want:

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.

mahadev sutar
  • 171
  • 2
  • 16

1 Answers1

1

Use this query to fetch month your query will show only single month

                  SELECT CASE
                  WHEN salary_amt IS NULL THEN 0 ELSE salary_amt 
                  END as salary_amt
                  FROM
                  (
                      SELECT 1 AS MONTH
                       UNION SELECT 2 AS MONTH
                       UNION SELECT 3 AS MONTH
                       UNION SELECT 4 AS MONTH
                       UNION SELECT 5 AS MONTH
                       UNION SELECT 6 AS MONTH
                       UNION SELECT 7 AS MONTH
                       UNION SELECT 8 AS MONTH
                       UNION SELECT 9 AS MONTH
                       UNION SELECT 10 AS MONTH
                       UNION SELECT 11 AS MONTH
                       UNION SELECT 12 AS MONTH
                  ) as meses
                LEFT JOIN salaryData e ON meses.MONTH = MONTH(STR_TO_DATE(SALARY_DATE,'%d-%b-%y')) GROUP BY meses.MONTH
siddhesh
  • 563
  • 1
  • 9
  • 15