且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

数据表将组合框添加为列

更新时间:2022-06-13 09:08:31

我曾经遇到过同样问题的你们的解决方案。创建组合框并添加到列12 ...注释.. Ozlem。

This is the solution I used for you guys who experienced the same problem. Creates comboboxes and adds to column 12..Regards.. Ozlem.

        function init(){

            //http://***.com/questions/2759837/adding-dropdown-list-to-the-particular-column-using-jquery

            var ind = 0;
            var year    = 2010;
            //var options = getYears(year, 3);
            $.each($('#rulesTable td:nth-child(12)'), function () {

                //creates a combobox
                var select  = document.createElement('select');
                select.setAttribute('class','year');
                select.setAttribute('name',ind+''); 
                select.setAttribute('id','comboYear'+ind); 
                select.innerHTML = '<option value=2010>2010</option><option value=2011>2011</option><option value=2012>2012</option>'; 

                /*for (var i= 0 ; i<options.length; i++){
                    var nextOption = options[i];                        
                    select.appendChild(nextOption);
                }*/
                $(this).append(select);
                $('#comboYear'+ind).change(function () {

                    var comboId = $(this).attr('id');
                    var comboIndex = $(this).attr('name');
                    var yearSelected = $('#'+comboId+' option:selected').text();
                    var propertyId = rulesTableGlobal.fnGetData()[comboIndex][0];
                    //alert(text);
                    upDateRow(propertyId, yearSelected, comboIndex );

                });

                year = year+1;
                ind++;                  

            });

        }