Guest User

Untitled

a guest
Mar 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. var estado = [
  2. "Situação 1",
  3. "Situação 2"
  4. ];
  5.  
  6. $(document).ready(function () {
  7. var table = $('#example').DataTable({
  8. "columns": [
  9.  
  10. { "data": [0], "orderable":false},
  11. { "data": [1], "orderable":false},
  12. { "data": [2], "orderable":false},
  13. { "data": [3]},
  14. { "data": [4], "type":'date-br'},
  15. { "data": [5], "orderable":false},
  16. {
  17. // criação do campo select no datatables
  18. "render": function(d,t,r){
  19.  
  20. var $select = $('<select id="MySelect"></select>', {
  21. "id": r[0]+"start",
  22. "value": d
  23. });
  24.  
  25. $.each(estado, function(k,v){
  26. var $option = $("<option></option>", {
  27. "text": v,
  28. "value": v
  29. });
  30.  
  31. if(d === v){
  32. $option.attr("selected", "selected")
  33. }
  34. $select.append($option);
  35. });
  36.  
  37. return $select.prop("outerHTML");
  38.  
  39. }
  40. }
  41. ]
  42. });
  43.  
  44. //pega os valores de cada option
  45.  
  46. $('#example').change( function() {
  47. var vals = []
  48. var sel = document.getElementById('MySelect');
  49. for (var i=0, n=sel.options.length;i<n;i++) {
  50. if (sel.options[i].text) vals.push(sel.options[i].text);
  51. }
  52. console.log(vals);
  53. });
  54.  
  55. […]
  56. 0: "Situação 1"
  57. 1: "Situação 2"
  58. length: 2
  59. proto: Array []
Add Comment
Please, Sign In to add comment