2

I have a HTML table having Drop down links to several columns.

I have already achieved that if someone click on link then it will forward to that link.

What I want to achieve is, like I have different HTML table which I want to call on the same page when on-click event occurred for the particular selected drop down column.

This is my code

<div id="tbl"></div>

    <ul id="contextMenu" class="dropdown-menu" role="menu">
      <li><a href="test1.html" class="link1">report1</a></li>
      <li><a href="" class="Link2">report2</a></li>
    </ul>

    $(window).load(function() {
        $dropdown = $("#contextMenu");
        $(".actionButton").click(function() {
          //get row ID

          //move dropdown menu
          $(this).after($dropdown);
          //update links

          $(this).dropdown();
        });
      });

    data= [
           {
             "amount": 291589,
             "billdate": "2018-08-01",
             "outlet": "JAYANAGAR"
           },
           {
             "amount": 58337,
             "billdate": "2018-08-01",
             "outlet": "MALLESHWARAM"
           },
           {
             "amount": 65970,
             "billdate": "2018-08-01",
             "outlet": "KOLAR"
           },
           {
             "amount": 296125,
             "billdate": "2018-08-02",
             "outlet": "JAYANAGAR"
           },
           {
             "amount": 56545,
             "billdate": "2018-08-02",
             "outlet": "MALLESHWARAM"
           },
           {
             "amount": 72213,
             "billdate": "2018-08-02",
             "outlet": "KOLAR"
           },
           {
             "amount": 346605,
             "billdate": "2018-08-03",
             "outlet": "JAYANAGAR"
           },
           {
             "amount": 62459,
             "billdate": "2018-08-03",
             "outlet": "MALLESHWARAM"
           },
           {
             "amount": 65248,
             "billdate": "2018-08-03",
             "outlet": "KOLAR"
           },
           {
             "amount": 518212,
             "billdate": "2018-08-04",
             "outlet": "JAYANAGAR"
           },
           {
             "amount": 104801,
             "billdate": "2018-08-04",
             "outlet": "MALLESHWARAM"
           },
           {
             "amount": 138151,
             "billdate": "2018-08-04",
             "outlet": "KOLAR"
           },
           {
             "amount": 628358,
             "billdate": "2018-08-05",
             "outlet": "JAYANAGAR"
           },
           {
             "amount": 115223,
             "billdate": "2018-08-05",
             "outlet": "MALLESHWARAM"
           },
           {
             "amount": 134107,
             "billdate": "2018-08-05",
             "outlet": "KOLAR"
           },
           {
             "amount": 177866,
             "billdate": "2018-08-06",
             "outlet": "JAYANAGAR"
           },
           {
             "amount": 66095,
             "billdate": "2018-08-06",
             "outlet": "KOLAR"
           },
           {
             "amount": 284069,
             "billdate": "2018-08-07",
             "outlet": "JAYANAGAR"
           },
           {
             "amount": 58789,
             "billdate": "2018-08-07",
             "outlet": "MALLESHWARAM"
           },
           {
             "amount": 67886,
             "billdate": "2018-08-07",
             "outlet": "KOLAR"
           },
           {
             "amount": 313128,
             "billdate": "2018-08-08",
             "outlet": "JAYANAGAR"
           },
           {
             "amount": 59939,
             "billdate": "2018-08-08",
             "outlet": "MALLESHWARAM"
           },
           {
             "amount": 68558,
             "billdate": "2018-08-08",
             "outlet": "KOLAR"
           }
         ]

         let formatData = function (data) {

                        let billdates = [];
                        let outlets = [];
                        data.forEach(element => {
                            if (billdates.indexOf(element.billdate) == -1) {
                                billdates.push(element.billdate);
                            }
                            if (outlets.indexOf(element.outlet) == -1) {
                                outlets.push(element.outlet);
                            }
                        });
                        return {
                            data: data,
                            billdates: billdates,
                            outlets: outlets,

                        };
                    };



                    let renderTable = function (data) {
                        billdates = data.billdates;
                        outlets = data.outlets;
                        data = data.data;
                        let tbl = document.getElementById("tbl");
                        let table = document.createElement("table");
                        let thead = document.createElement("thead");
                        let headerRow = document.createElement("tr");
                        let th = document.createElement("th");
                        th.innerHTML = "Bill___Date";
                         th.classList.add("text-center");
                        headerRow.appendChild(th);
                        let grandTotal = 0;
                        let outletWiseTotal = {};
                        th = document.createElement("th");
                        th.innerHTML = "Total";
                        th.classList.add("text-center");
                        headerRow.appendChild(th);

                        outlets.forEach(element => {
                            th = document.createElement("th");
                            th.innerHTML = element;
                            th.classList.add("text-center");
                            headerRow.appendChild(th);
                            outletWiseTotal[element] = 0;
                            data.forEach(el => {
                                if (el.outlet == element) {
                                    outletWiseTotal[element] += parseInt(el.amount);
                                }
                            });
                            grandTotal += outletWiseTotal[element];
                        });


                        thead.appendChild(headerRow);
                        headerRow = document.createElement("tr");
                        th = document.createElement("th");
                        th.innerHTML = "Total";
                       th.classList.add("text-center");

                        headerRow.appendChild(th);

                        outlets.forEach(element => {
                            th = document.createElement("th");
                            th.innerHTML = outletWiseTotal[element];
                             th.classList.add("text-right");   //ol totals
                            headerRow.appendChild(th);
                        });
                      /*  th = document.createElement("th");
                      a = document.createElement("a");
                      // th.innerHTML = "Action drop"; // removed
                      th.classList.add("text-center");
                      th.classList.add("dropdown");
                      a.classList.add("btn-default");
                      a.classList.add("actionButton");


                      // added
                      a.setAttribute("data-toggle", "dropdown");
                      a.innerHTML = "Action drop";
                      th.appendChild(a); // added

                      headerRow.appendChild(th); */
                        th = document.createElement("th");
                        th.innerHTML = grandTotal;
                          th.classList.add("text-right");  // grand total
                  /*  console.log(grandTotal);*/
                       // headerRow.appendChild(th);
                    headerRow.insertBefore(th , headerRow.children[1] );
                        thead.appendChild(headerRow);
                        table.appendChild(thead);

                        let tbody = document.createElement("tbody");


                        billdates.forEach(element => {
                            let row = document.createElement("tr");  
                            td = document.createElement("td");
                            td.innerHTML = element;
                            row.appendChild(td);
                            let total = 0;
                            outlets.forEach(outlet => {
                                let el = 0;
                                data.forEach(d => {
                                    if (d.billdate == element && d.outlet == outlet) {
                                        total += parseInt(d.amount);
                                        el = d.amount;
                                    }
                                });
                               /*  td = document.createElement("td");
                                td.innerHTML = el; */



                               td = document.createElement("td");
                              a = document.createElement("a");
                              // th.innerHTML = "Action drop"; // removed
                              td.classList.add("text-right");
                              td.classList.add("dropdown");
                              a.classList.add("btn-default");
                              a.classList.add("actionButton");


                              // added
                              a.setAttribute("data-toggle", "dropdown");
                              a.innerHTML = el;
                              td.appendChild(a); // added

                              row.appendChild(td);



                                 /* td.classList.add("text-right"); //oldata
                                row.appendChild(td); */
                            });
                            /*console.log("row is : " , row.children )*/
                            td = document.createElement("td");
                            td.innerHTML = total;
                             td.classList.add("text-right"); //column total
                           // row.appendChild(td);
                            row.insertBefore(td , row.children[1] );
                            tbody.appendChild(row);

                        });

                        table.appendChild(tbody);

                        tbl.innerHTML = "";
                        tbl.appendChild(table);
                        table.classList.add("table");
                        table.classList.add("table-striped");
                        table.classList.add("table-bordered");
                       table.classList.add("table-hover");
                    }
                     let formatedData = formatData(data);
                     renderTable(formatedData);

Here, I have provided a link ('test.html') to check.

In my HTML table, I have three columns named as JAYANAGAR,MALLESHWARAM and KOLAR. For these three columns, I have drop-downs named as Report1 and Report2. When user clicks on Report1 drop down of column JAYANAGAR, it should show the Jayanagar data only. For all the three columns, I have links or new tables already in my code. I just want to filter the dynamic call when column dropdown is clicked and redirect or render that table assigned to that link.

  • If user clicks dropdown of column jayanagar, then it should show jayanagar data in some div tag of same page
  • If user clicks dropdown of Maleeshwaram, then it should show malleshwaram data in same div tag .

  • I already have filtered data on the basis of outlets. Just want to do it at java script end.

  • I just want to know which column's drop-down user is clicking.

Fiddle

halfer
  • 19,824
  • 17
  • 99
  • 186
manish thakur
  • 760
  • 9
  • 35
  • 76

2 Answers2

2

You already have common function all you need is to filter the data as per the click and your done, I have filtered your data and bind to the particular div. It should work now.

This part is important, you need to filter and bind the data to different div.

$(".dropdown-menu li a").click(function() {

    if (currentlyClickedPlace !== "" && currentlyClickedPlace !== undefined) {
      var filteredData = data.filter(a => a.outlet === currentlyClickedPlace);
      let formatedData = formatData(filteredData);
      renderTable(formatedData, 'test', '');
    }
  })

var currentlyClickedPlace = "";
$(window).load(function() {
  $dropdown = $("#contextMenu");
  $(".actionButton").click(function() {
    //move dropdown menu
    $(this).after($dropdown);
    //update links
    $(this).dropdown();

    currentlyClickedPlace = $(this).attr("data-place");
  });
  $(".dropdown-menu li a").click(function() {
    if (currentlyClickedPlace !== "" && currentlyClickedPlace !== undefined) {
      var filteredData = data.filter(a => a.outlet === currentlyClickedPlace);
      let formatedData = formatData(filteredData);
      renderTable(formatedData, 'test', '');
    }
  })
});

data = [{
    "amount": 291589,
    "billdate": "2018-08-01",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 58337,
    "billdate": "2018-08-01",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 65970,
    "billdate": "2018-08-01",
    "outlet": "KOLAR"
  },
  {
    "amount": 296125,
    "billdate": "2018-08-02",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 56545,
    "billdate": "2018-08-02",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 72213,
    "billdate": "2018-08-02",
    "outlet": "KOLAR"
  },
  {
    "amount": 346605,
    "billdate": "2018-08-03",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 62459,
    "billdate": "2018-08-03",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 65248,
    "billdate": "2018-08-03",
    "outlet": "KOLAR"
  },
  {
    "amount": 518212,
    "billdate": "2018-08-04",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 104801,
    "billdate": "2018-08-04",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 138151,
    "billdate": "2018-08-04",
    "outlet": "KOLAR"
  },
  {
    "amount": 628358,
    "billdate": "2018-08-05",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 115223,
    "billdate": "2018-08-05",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 134107,
    "billdate": "2018-08-05",
    "outlet": "KOLAR"
  },
  {
    "amount": 177866,
    "billdate": "2018-08-06",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 66095,
    "billdate": "2018-08-06",
    "outlet": "KOLAR"
  },
  {
    "amount": 284069,
    "billdate": "2018-08-07",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 58789,
    "billdate": "2018-08-07",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 67886,
    "billdate": "2018-08-07",
    "outlet": "KOLAR"
  },
  {
    "amount": 313128,
    "billdate": "2018-08-08",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 59939,
    "billdate": "2018-08-08",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 68558,
    "billdate": "2018-08-08",
    "outlet": "KOLAR"
  }
]

let formatData = function(data) {

  let billdates = [];
  let outlets = [];
  data.forEach(element => {
    if (billdates.indexOf(element.billdate) == -1) {
      billdates.push(element.billdate);
    }
    if (outlets.indexOf(element.outlet) == -1) {
      outlets.push(element.outlet);
    }
  });
  return {
    data: data,
    billdates: billdates,
    outlets: outlets,

  };
};



let renderTable = function(data, divId, filterdata) {
  billdates = data.billdates;
  outlets = data.outlets;
  data = data.data;
  let tbl = document.getElementById(divId);
  let table = document.createElement("table");
  let thead = document.createElement("thead");
  let headerRow = document.createElement("tr");
  let th = document.createElement("th");
  th.innerHTML = "Bill___Date";
  th.classList.add("text-center");
  headerRow.appendChild(th);
  let grandTotal = 0;
  let outletWiseTotal = {};
  th = document.createElement("th");
  th.innerHTML = "Total";
  th.classList.add("text-center");
  headerRow.appendChild(th);

  outlets.forEach(element => {
    th = document.createElement("th");
    th.innerHTML = element;
    th.classList.add("text-center");
    headerRow.appendChild(th);
    outletWiseTotal[element] = 0;
    data.forEach(el => {
      if (el.outlet == element) {
        outletWiseTotal[element] += parseInt(el.amount);
      }
    });
    grandTotal += outletWiseTotal[element];
  });


  thead.appendChild(headerRow);
  headerRow = document.createElement("tr");
  th = document.createElement("th");
  th.innerHTML = "Total";
  th.classList.add("text-center");

  headerRow.appendChild(th);

  outlets.forEach(element => {
    th = document.createElement("th");
    th.innerHTML = outletWiseTotal[element];
    th.classList.add("text-right"); //ol totals
    headerRow.appendChild(th);
  });
  /*  th = document.createElement("th");
                   a = document.createElement("a");
                   // th.innerHTML = "Action drop"; // removed
                   th.classList.add("text-center");
                   th.classList.add("dropdown");
                   a.classList.add("btn-default");
                   a.classList.add("actionButton");
                  

                   // added
                   a.setAttribute("data-toggle", "dropdown");
                   a.innerHTML = "Action drop";
                   th.appendChild(a); // added

                   headerRow.appendChild(th); */
  th = document.createElement("th");
  th.innerHTML = grandTotal;
  th.classList.add("text-right"); // grand total
  /*  console.log(grandTotal);*/
  // headerRow.appendChild(th);
  headerRow.insertBefore(th, headerRow.children[1]);
  thead.appendChild(headerRow);
  table.appendChild(thead);

  let tbody = document.createElement("tbody");

  billdates.forEach(element => {
    let row = document.createElement("tr");
    td = document.createElement("td");
    td.innerHTML = element;
    row.appendChild(td);
    let total = 0;
    outlets.forEach(outlet => {
      let el = 0;
      data.forEach(d => {
        if (d.billdate == element && d.outlet == outlet) {
          total += parseInt(d.amount);
          el = d.amount;
        }
      });
      /*  td = document.createElement("td");
       td.innerHTML = el; */



      td = document.createElement("td");
      a = document.createElement("a");
      // th.innerHTML = "Action drop"; // removed
      td.classList.add("text-right");
      td.classList.add("dropdown");
      a.classList.add("btn-default");
      a.classList.add("actionButton");

      a.setAttribute("data-place", outlet);
      // added
      a.setAttribute("data-toggle", "dropdown");
      a.innerHTML = el;
      td.appendChild(a); // added

      row.appendChild(td);



      /* td.classList.add("text-right"); //oldata
                             row.appendChild(td); */
    });
    /*console.log("row is : " , row.children )*/
    td = document.createElement("td");
    td.innerHTML = total;
    td.classList.add("text-right"); //column total
    // row.appendChild(td);
    row.insertBefore(td, row.children[1]);
    tbody.appendChild(row);

  });

  table.appendChild(tbody);

  tbl.innerHTML = "";
  tbl.appendChild(table);
  table.classList.add("table");
  table.classList.add("table-striped");
  table.classList.add("table-bordered");
  table.classList.add("table-hover");
}
let formatedData = formatData(data);
renderTable(formatedData, 'tbl', '');
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>JS Bin</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.2.js"></script>
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" />

<div id="tbl"></div>
<div id="test"></div>
<ul id="contextMenu" class="dropdown-menu" role="menu">
  <li><a href="#" class="link1">Report1</a></li>
  <li><a href="#" class="Link2">Report2</a></li>
</ul>

EDIT: you can bind the separate links for the report 1 and report 2 and call ajax functions

var currentlyClickedPlace = "";
$(window).load(function() {
  $dropdown = $("#contextMenu");
  $(".actionButton").click(function() {
    //move dropdown menu
    $(this).after($dropdown);
    //update links
    $(this).dropdown();

    currentlyClickedPlace = $(this).attr("data-place");
  });
  $(".link1").click(function(){
    alert('report 1 is clicked in ' + currentlyClickedPlace);
    //call ajax and bind the data into test div
  });
  $(".Link2").click(function(){
    alert('report 2 is clicked in ' + currentlyClickedPlace);
    //call ajax and bind the data into test div
  });
});

data = [{
    "amount": 291589,
    "billdate": "2018-08-01",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 58337,
    "billdate": "2018-08-01",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 65970,
    "billdate": "2018-08-01",
    "outlet": "KOLAR"
  },
  {
    "amount": 296125,
    "billdate": "2018-08-02",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 56545,
    "billdate": "2018-08-02",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 72213,
    "billdate": "2018-08-02",
    "outlet": "KOLAR"
  },
  {
    "amount": 346605,
    "billdate": "2018-08-03",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 62459,
    "billdate": "2018-08-03",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 65248,
    "billdate": "2018-08-03",
    "outlet": "KOLAR"
  },
  {
    "amount": 518212,
    "billdate": "2018-08-04",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 104801,
    "billdate": "2018-08-04",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 138151,
    "billdate": "2018-08-04",
    "outlet": "KOLAR"
  },
  {
    "amount": 628358,
    "billdate": "2018-08-05",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 115223,
    "billdate": "2018-08-05",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 134107,
    "billdate": "2018-08-05",
    "outlet": "KOLAR"
  },
  {
    "amount": 177866,
    "billdate": "2018-08-06",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 66095,
    "billdate": "2018-08-06",
    "outlet": "KOLAR"
  },
  {
    "amount": 284069,
    "billdate": "2018-08-07",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 58789,
    "billdate": "2018-08-07",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 67886,
    "billdate": "2018-08-07",
    "outlet": "KOLAR"
  },
  {
    "amount": 313128,
    "billdate": "2018-08-08",
    "outlet": "JAYANAGAR"
  },
  {
    "amount": 59939,
    "billdate": "2018-08-08",
    "outlet": "MALLESHWARAM"
  },
  {
    "amount": 68558,
    "billdate": "2018-08-08",
    "outlet": "KOLAR"
  }
]

let formatData = function(data) {

  let billdates = [];
  let outlets = [];
  data.forEach(element => {
    if (billdates.indexOf(element.billdate) == -1) {
      billdates.push(element.billdate);
    }
    if (outlets.indexOf(element.outlet) == -1) {
      outlets.push(element.outlet);
    }
  });
  return {
    data: data,
    billdates: billdates,
    outlets: outlets,

  };
};



let renderTable = function(data, divId, filterdata) {
  billdates = data.billdates;
  outlets = data.outlets;
  data = data.data;
  let tbl = document.getElementById(divId);
  let table = document.createElement("table");
  let thead = document.createElement("thead");
  let headerRow = document.createElement("tr");
  let th = document.createElement("th");
  th.innerHTML = "Bill___Date";
  th.classList.add("text-center");
  headerRow.appendChild(th);
  let grandTotal = 0;
  let outletWiseTotal = {};
  th = document.createElement("th");
  th.innerHTML = "Total";
  th.classList.add("text-center");
  headerRow.appendChild(th);

  outlets.forEach(element => {
    th = document.createElement("th");
    th.innerHTML = element;
    th.classList.add("text-center");
    headerRow.appendChild(th);
    outletWiseTotal[element] = 0;
    data.forEach(el => {
      if (el.outlet == element) {
        outletWiseTotal[element] += parseInt(el.amount);
      }
    });
    grandTotal += outletWiseTotal[element];
  });


  thead.appendChild(headerRow);
  headerRow = document.createElement("tr");
  th = document.createElement("th");
  th.innerHTML = "Total";
  th.classList.add("text-center");

  headerRow.appendChild(th);

  outlets.forEach(element => {
    th = document.createElement("th");
    th.innerHTML = outletWiseTotal[element];
    th.classList.add("text-right"); //ol totals
    headerRow.appendChild(th);
  });
  /*  th = document.createElement("th");
                   a = document.createElement("a");
                   // th.innerHTML = "Action drop"; // removed
                   th.classList.add("text-center");
                   th.classList.add("dropdown");
                   a.classList.add("btn-default");
                   a.classList.add("actionButton");
                  

                   // added
                   a.setAttribute("data-toggle", "dropdown");
                   a.innerHTML = "Action drop";
                   th.appendChild(a); // added

                   headerRow.appendChild(th); */
  th = document.createElement("th");
  th.innerHTML = grandTotal;
  th.classList.add("text-right"); // grand total
  /*  console.log(grandTotal);*/
  // headerRow.appendChild(th);
  headerRow.insertBefore(th, headerRow.children[1]);
  thead.appendChild(headerRow);
  table.appendChild(thead);

  let tbody = document.createElement("tbody");

  billdates.forEach(element => {
    let row = document.createElement("tr");
    td = document.createElement("td");
    td.innerHTML = element;
    row.appendChild(td);
    let total = 0;
    outlets.forEach(outlet => {
      let el = 0;
      data.forEach(d => {
        if (d.billdate == element && d.outlet == outlet) {
          total += parseInt(d.amount);
          el = d.amount;
        }
      });
      /*  td = document.createElement("td");
       td.innerHTML = el; */



      td = document.createElement("td");
      a = document.createElement("a");
      // th.innerHTML = "Action drop"; // removed
      td.classList.add("text-right");
      td.classList.add("dropdown");
      a.classList.add("btn-default");
      a.classList.add("actionButton");

      a.setAttribute("data-place", outlet);
      // added
      a.setAttribute("data-toggle", "dropdown");
      a.innerHTML = el;
      td.appendChild(a); // added

      row.appendChild(td);



      /* td.classList.add("text-right"); //oldata
                             row.appendChild(td); */
    });
    /*console.log("row is : " , row.children )*/
    td = document.createElement("td");
    td.innerHTML = total;
    td.classList.add("text-right"); //column total
    // row.appendChild(td);
    row.insertBefore(td, row.children[1]);
    tbody.appendChild(row);

  });

  table.appendChild(tbody);

  tbl.innerHTML = "";
  tbl.appendChild(table);
  table.classList.add("table");
  table.classList.add("table-striped");
  table.classList.add("table-bordered");
  table.classList.add("table-hover");
}
let formatedData = formatData(data);
renderTable(formatedData, 'tbl', '');
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>JS Bin</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.2.js"></script>
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" />

<div id="tbl"></div>
<div id="test"></div>
<ul id="contextMenu" class="dropdown-menu" role="menu">
  <li><a href="#" class="link1">Report1</a></li>
  <li><a href="#" class="Link2">Report2</a></li>
</ul>
Just code
  • 13,553
  • 10
  • 51
  • 93
  • what if i click on Report2 (dropdown) ? – manish thakur Dec 04 '18 at 05:01
  • what i want is when user click on report 1 or report 2 i want to make two different ajax call which will have the value of any of clicked jayanagar,malleshwaram,or kolar or its respective date ..because all these valuei have to store and will use to populate the new table on clicking on report1 or report2 – manish thakur Dec 04 '18 at 05:24
  • @manishthakur check my edit: you will get an idea how to do that. – Just code Dec 04 '18 at 05:31
  • hey how can i get the respective bill date also which dropdown is clicked? ` currentlyClickedPlace = $(this).attr("data-place");` this one is giving header what if i want the respective bill date on clicking report1 or 2 ? – manish thakur Dec 04 '18 at 05:46
  • hey sir i am facing issue in one of my code i have posted that on SO also, but didn't got any answer till now can you please help me out https://stackoverflow.com/questions/55919420/how-to-make-html-table-expand-on-click – manish thakur May 06 '19 at 05:38
  • @manishthakur is this something you want? https://stackblitz.com/edit/js-nmkpdr?file=index.js this is general approach, you can calculate based on that – Just code May 07 '19 at 06:11
  • @manishthakur sorry, the link was broken https://stackblitz.com/edit/js-nmkpdr?file=index.html – Just code May 07 '19 at 06:25
  • hey this what i was expecting now the issue is when i initially render the page all the items are expanded already i want initially brand name only should be there than when i click on plus sign then it should expand – manish thakur May 07 '19 at 06:26
  • @manishthakur I do not see that issue, where do you see rows expanded? – Just code May 07 '19 at 06:29
  • yup in you snippet it is working fine, but in my code when i am copying it says error ` let data = data.data;` error as `SyntaxError: redeclaration of formal parameter data:768:6note: Previously declared at line 763, column 29` – manish thakur May 07 '19 at 06:34
  • please make a code snippet in SO i will check there or a fiddle – manish thakur May 07 '19 at 06:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/192940/discussion-between-just-code-and-manish-thakur). – Just code May 07 '19 at 06:46
  • sir please help me in filtering this with NA i don't want NA to be in brand name `if (!maxUniqueForOutlets[element["brandname"]]) { maxUniqueForOutlets[element["brandname"]] = []; of brandname and itemname } if ((maxUniqueForOutlets[element["brandname"]]!=="NA") && maxUniqueForOutlets[element["brandname"]].indexOf(element["itemname"]) == -1 && (element.itemname) !== "NA") { maxUniqueForOutlets[element["brandname"]].push(element["itemname"]); }` i have figured out every thing now just stuck here – manish thakur May 07 '19 at 09:55
0

It was difficult understanding your question. So, as per my understanding, I am answering.

  1. Create a DIV tag. give it an id "columnData".
  2. Add an onclick attribute to the LI tag and assign it a function showColumnData(columnName).
  3. In the function, you will require to pass the columnName (JAYANAGAR) so as to identify the column, this you can get from data[index].outlet object.
  4. Next, createElement table and append the data from the data array (filtered via column name) and yes before appending do a getElementById() and remove any child nodes removeChild() to already existing data.

  5. Append the tableElement to the DIV via id columnData.

Melroy Fernandes
  • 371
  • 1
  • 5
  • 16
  • hey can you provide me a fiddle link with small example please? – manish thakur Dec 03 '18 at 08:16
  • Ya so input only `data[0].outlet` in the `showColumnData()` function. whatever value is there in data[0].outlet will be passed over. – Melroy Fernandes Dec 03 '18 at 08:18
  • hey how can i put any value..like i have `data[0].outlet` in the `ShowColumnData()` but user has selected malleshwaram which is on index 1..then what to do – manish thakur Dec 03 '18 at 08:20
  • Oh, I am sorry, I thought the `LI` tags are generated dynamically. So, you will have to add a `getColumnName(columnName)` function to the `TD` tag (`onclick` attribute) while generating the table and assign the `columnName` to global variable `selectedColumn` and then use this to pass in the `showColumnData()` function. – Melroy Fernandes Dec 03 '18 at 08:52
  • hey please help me out in this i am stuck here please – manish thakur Dec 03 '18 at 09:04
  • can i generate that `li` tag dynamically ? – manish thakur Dec 03 '18 at 09:11