Need to add dropdown as a column loading static data

Need to add dropdown as a column loading static data

suma ksuma k Posts: 4Questions: 1Answers: 0

I am new to data tables.I would like to add a dropdown with two values open,close and based on selected values the following changes will happen.Please help me with this

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @suma k ,

    Would something like this do it?

    Cheers,

    Colin

  • suma ksuma k Posts: 4Questions: 1Answers: 0

    hi colin,
    No.I would like to add dropdown in the data as we enter data for other columns in the datatable
    ex-:name|age|dropdown column
    sam|12|dropdown with values
    marry|14|dropdown with values

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    Maybe this example will help get you started. Please post if you have any questions.
    http://live.datatables.net/yogayixa/1/edit

    Kevin

  • suma ksuma k Posts: 4Questions: 1Answers: 0

    Perfect Example.
    Thanks kevin.

  • suma ksuma k Posts: 4Questions: 1Answers: 0

    As you can see in my code iam trying to create a link for the data inside the dropdown but it is coimng as a data not the link.Not sure why

    {
    "data": "EnableReopenAction",
    render: function (data, type, row) {
    if (data == true) {

                                 namesOption = [];
                                 namesOption.push({ id: 1, name: "" });
                                 var name1 = '<a href="#" onclick="ControlActionIcon(' + row.multisiteid + ',' + row.reg_nbr + ',' + row.IsAssigendToProfile + ')" >' + data + '</a>' ;
                                 namesOption.push({ id: 2, name:name1 });
                                 var $select = $('<select class="team_ddl"></select>',
                                     {
                                         id: row.id,
                                         value: row.name
                                     });
                                 $.each(namesOption, function (k, v) {
                                     if (1 == 1) {   //changed this, not sure why the original code has it
                                         var $option = $("<option></option>",
                                         {
                                             text: v.name,
                                             value: v.id
                                         });
    
                                         //if selected_id = id then this is the selected value
                                         if (row.selected_id == v.id) {  //use == instead of ===
                                             $option.attr("selected", "selected");
                                         }
                                         $select.append($option);
                                     }
                                 });
                                 return $select.prop("outerhtml");
                             }
                             else {
                                         data = "";
                                         return data;
                                     }
                         }
    
    
                },
    
  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited November 2018

    Not sure you can have links in the select options. This SO thread may help.

    Kevin

This discussion has been closed.