Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var estado = [
- "Situação 1",
- "Situação 2"
- ];
- $(document).ready(function () {
- var table = $('#example').DataTable({
- "columns": [
- { "data": [0], "orderable":false},
- { "data": [1], "orderable":false},
- { "data": [2], "orderable":false},
- { "data": [3]},
- { "data": [4], "type":'date-br'},
- { "data": [5], "orderable":false},
- {
- // criação do campo select no datatables
- "render": function(d,t,r){
- var $select = $('<select id="MySelect"></select>', {
- "id": r[0]+"start",
- "value": d
- });
- $.each(estado, function(k,v){
- var $option = $("<option></option>", {
- "text": v,
- "value": v
- });
- if(d === v){
- $option.attr("selected", "selected")
- }
- $select.append($option);
- });
- return $select.prop("outerHTML");
- }
- }
- ]
- });
- //pega os valores de cada option
- $('#example').change( function() {
- var vals = []
- var sel = document.getElementById('MySelect');
- for (var i=0, n=sel.options.length;i<n;i++) {
- if (sel.options[i].text) vals.push(sel.options[i].text);
- }
- console.log(vals);
- });
- […]
- 0: "Situação 1"
- 1: "Situação 2"
- length: 2
- proto: Array []
Add Comment
Please, Sign In to add comment