gpt4 book ai didi

jquery - 数据表添加组合框作为列

转载 作者:行者123 更新时间:2023-12-01 01:11:04 24 4
gpt4 key购买 nike

我有一个使用 Datatables 的数据表。我已经创建并填写了表格,如下所示。现在我需要实现一个组合框(假设我有 2010, 2011,2012)以允许用户选择年份。然后,当用户单击放置在表中的“查看”或“修改”链接时,所选年份将作为参数传递到另一个页面。

现在如何将我的年份列变成组合框?

        rulesTableGlobal = $('#rulesTable').dataTable( {
//"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns": [
{ "sTitle": "Id", "sWidth" : "20px" },
{ "sTitle": "Property ID" , "sWidth" : "20px"},
{ "sTitle": "Adress" , "sWidth" : "130px"},
{ "sTitle": "Suburb" , "sWidth" : "50px"},
{ "sTitle": "Bond", "sWidth" : "25px" },
{ "sTitle": "Year", "sWidth" : "25px" , "aType": "dom-select"},
{ "sTitle": "View or Modify" , "sWidth" : "50px"}]

});

function addPropertyToTable( lt_id, lt_uid, address, suburb_name, min_guests, max_guests,
bondFee,cleaningFee,bookingServiceFee, weekly_rate,nightly_rate){

var _lt_id = "\'" + lt_id + "\'";
var viewLink = '<A href="#" onclick="forwardDetails('+_lt_id+');">View and Modify</A>';
var year= "";

$('#rulesTable').dataTable().fnAddData( [
lt_id, lt_uid, address, suburb_name, bondFee,cleaningFee,bookingServiceFee, weekly_rate,nightly_rate, min_guests, max_guests, year, viewLink ] );


}

});

}

最佳答案

这是我为遇到同样问题的人使用的解决方案。创建组合框并添加到第 12 列..问候..Ozlem。

        function init(){

//http://stackoverflow.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++;

});

}

关于jquery - 数据表添加组合框作为列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4515924/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com