update html table when dropdown value change

Manjunath Siddappa

From json i need to update the table based on month and year from javascript.

Any approach is fine for me

For reference i have created the FIDDLEbut it is not complete yet, just want to show the real environment

link: :http://jsfiddle.net/qytdu1zs/1/

enter image description here

HTML

<div class="dropdown">
    <select name="one" class="dropdown-select">
    <option value="">Select Year</option>
    <option value="0">2014</option>
    <option value="1">2013</option>
    <option value="2">2012</option>
    </select>           
</div>


<div class="dropdown ">
    <select name="two" class="dropdown-select">
    <option value="">Select Month</option>
    <option value="0">January</option>
    <option value="1">February</option>
    <option value="2">March</option>
    <option value="3">April</option>
    <option value="4">May</option>
    <option value="5">June</option>
    <option value="6">July</option>
    <option value="7">August</option>
    <option value="8">September</option>
    <option value="9">October</option>
    <option value="10">November</option>
    <option value="11">December</option>
    </select>           
</div>

html Table

<div id="example1"></div>

Jquery - i have used mustache.js

    $.ajax({
    url : 'data/front_finance.json',
    dataType : 'json',
    success : function (json) {

        var customer = $('#example1').columns({
                data : json,
                schema : [{
                        "header" : "ID",
                        "key" : "id",
                        "template" : "{{id}}"
                    }, {
                        "header" : "Name",
                        "key" : "name",
                        "template" : '<a href="#" onclick="javascript:ShowDialog(this.id);return false;" id="{{name}}" class="topopup">{{name}}</a>'
                    }, {
                        "header" : "Actual",
                        "key" : "actual"
                    }, {
                        "header" : "Target",
                        "key" : "target"
                    }, {
                        "header" : "Status",
                        "key" : "status",
                        "template" : "<img src ='{{status}}' alt='{{status}}'></img>"
                    }, {
                        "header" : "Trend",
                        "key" : "trend",
                        "template" : "<img src ='{{trend}}' alt='{{trend}}'></img>"
                    }
                ]
            });
    }
});

JSON

[
  {
    "year": "2013",
    "jan": [
      {
        "id": 1,
        "name": "data",
        "actual": "17",
        "target": "19",
        "status": "red",
        "trend": "down"
      }
    ],
    "Feb": [
      {
        "id": 2,
        "name": "data1",
        "actual": "10",
        "target": "19",
        "status": "red",
        "trend": "down"
      }
    ],
    "March": [
      {
        "id": 3,
        "name": "data2",
        "actual": "34",
        "target": "19",
        "status": "green",
        "trend": "down"
      }
    ]
  },
  {
    "year": "2014",
    "jan": [
      {
        "id": 1,
        "name": "data",
        "actual": "17",
        "target": "19",
        "status": "red",
        "trend": "down"
      }
    ],
    "Feb": [
      {
        "id": 2,
        "name": "data1",
        "actual": "10",
        "target": "19",
        "status": "red",
        "trend": "down"
      }
    ],
    "March": [
      {
        "id": 3,
        "name": "data2",
        "actual": "34",
        "target": "19",
        "status": "green",
        "trend": "down"
      }
    ]
  }
]
Akash Sarawagi

NEW FIDDLE FIDDLE

$(document).ready(function (){
cloneObj= $("#example1").clone(); 
$('select[name=one]').on('change', function() {
    var selectedYear=($("option:selected", this).text());
    if (selectedYear!="Select Year"){

    for (var a in data){

        if(data[a].year==selectedYear){

            objMonth=data[a];

            return false;
        }
         }
    }else{
    objMonth=null;
    }
});
$('select[name=two]').on('change', function() {
var selectedYear=($("option:selected",  $('select[name=one]')).text());
    if (selectedYear!="Select Year"){
         var selectedMonth=($("option:selected", this).text());
        var jsonValue=objMonth[MonthMap[selectedMonth]];
        $("#example1").replaceWith(cloneObj.clone());

        $('#example1').columns({ data : jsonValue});    
    }else{
    alert("Please Select year please");
    }
});
});

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

DropDown list doesnt update selected value

분류에서Dev

get selected value from dropdown in a table

분류에서Dev

Can Not Populate Dropdown When Placing Elements In Table

분류에서Dev

WPF Binding: How to prevent target update when source value does not change after input

분류에서Dev

Can't change value on update with JOIN

분류에서Dev

Cell Style Binding does not Update on Value Change

분류에서Dev

How to update multiple dropdown selects when user changes one selection

분류에서Dev

remove the value if i change to no using jquery select dropdown

분류에서Dev

How to update value in table in database, laravel?

분류에서Dev

Change HTML table style from Javascript function?

분류에서Dev

How to get selected value of dropdown when using partial view in mvc?

분류에서Dev

AngularJS update HTML when array is updated

분류에서Dev

How to change html input multiple value

분류에서Dev

jquery - change input value when go to next

분류에서Dev

Assign a Value to a HTML Table Cell using JQuery

분류에서Dev

Error when testing for the max value of a table?

분류에서Dev

Update $scope when contenteditable Elements Change with Angular.js

분류에서Dev

How to retrieve a key in a hash table and then update the value in Powershell?

분류에서Dev

Error Appears When Trying to Display MySQL Table Data in HTML Table

분류에서Dev

Kendo UI Grid from Html table - change event will not fire

분류에서Dev

Can't update value: 'Primary Key' has a temporary value while attempting to change the entity's state to 'Modified'

분류에서Dev

HTML dropdown list issues

분류에서Dev

Change color of HTML element based on previous value - CSS

분류에서Dev

php - change value to src attribute if 'cid:' are found in html document

분류에서Dev

Javascript value doesn't change when the variable contained in it increases

분류에서Dev

how to change the textfield value when the button is clicked in uitableviewcell iOS

분류에서Dev

read input text value when button click in table

분류에서Dev

ORA-02287 when inserting sequence value into Oracle table

분류에서Dev

angular bootstrap dropdown in a table cell

Related 관련 기사

  1. 1

    DropDown list doesnt update selected value

  2. 2

    get selected value from dropdown in a table

  3. 3

    Can Not Populate Dropdown When Placing Elements In Table

  4. 4

    WPF Binding: How to prevent target update when source value does not change after input

  5. 5

    Can't change value on update with JOIN

  6. 6

    Cell Style Binding does not Update on Value Change

  7. 7

    How to update multiple dropdown selects when user changes one selection

  8. 8

    remove the value if i change to no using jquery select dropdown

  9. 9

    How to update value in table in database, laravel?

  10. 10

    Change HTML table style from Javascript function?

  11. 11

    How to get selected value of dropdown when using partial view in mvc?

  12. 12

    AngularJS update HTML when array is updated

  13. 13

    How to change html input multiple value

  14. 14

    jquery - change input value when go to next

  15. 15

    Assign a Value to a HTML Table Cell using JQuery

  16. 16

    Error when testing for the max value of a table?

  17. 17

    Update $scope when contenteditable Elements Change with Angular.js

  18. 18

    How to retrieve a key in a hash table and then update the value in Powershell?

  19. 19

    Error Appears When Trying to Display MySQL Table Data in HTML Table

  20. 20

    Kendo UI Grid from Html table - change event will not fire

  21. 21

    Can't update value: 'Primary Key' has a temporary value while attempting to change the entity's state to 'Modified'

  22. 22

    HTML dropdown list issues

  23. 23

    Change color of HTML element based on previous value - CSS

  24. 24

    php - change value to src attribute if 'cid:' are found in html document

  25. 25

    Javascript value doesn't change when the variable contained in it increases

  26. 26

    how to change the textfield value when the button is clicked in uitableviewcell iOS

  27. 27

    read input text value when button click in table

  28. 28

    ORA-02287 when inserting sequence value into Oracle table

  29. 29

    angular bootstrap dropdown in a table cell

뜨겁다태그

보관