almende / vis

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
7.85k stars 1.48k forks source link

problem with manually template IE11 and EDGE #3984

Open aaroncreed opened 6 years ago

aaroncreed commented 6 years ago

Hi, good day

I tried to make a timeline with vis.js 4.21.0 and its work fine in GoogleChrome but in IE11 and EDGE disappeared all the content, load the json again and it still doing the same thing. If you play with them work fine but if you still insist in some one point case1 the timeline become like this:

case2

my code: ///json

  {
   [
    {
    "start": "2018-04-01T06:00:00.000Z",
    "fecha_asignacion": "2018-04-01 00:00:00",
    "termino_asignacion": "2018-04-03 23:59:00",
    "id_asignacion": 62,
    "id": 62,
    "idvehiculo": 1,
    "sucursal": 222,
    "empresa": 2,
    "idchofer": null,
    "vehicul": {
      "id_vehiculo": 1,
      "placas": "YR-1779-5"
    },
    "sucursall": {
      "id_sucursal": 222,
      "n_suc": "Suc. Itzaes"
    },
    "empresaa": {
      "id_empresa": 2,
      "n_empresa": "LA VIGA VIANA "
    },
    "choff": null
  },
  {
    "start": "2018-04-04T05:00:00.000Z",
    "fecha_asignacion": "2018-04-04 00:00:00",
    "termino_asignacion": "2018-04-27 23:59:00",
    "id_asignacion": 66,
    "id": 66,
    "idvehiculo": 1,
    "sucursal": 223,
    "empresa": 2,
    "idchofer": null,
    "vehicul": {
      "id_vehiculo": 1,
      "placas": "YR-1779-5"
    },
    "sucursall": {
      "id_sucursal": 223,
      "n_suc": "Suc. Valladolid"
    },
    "empresaa": {
      "id_empresa": 2,
      "n_empresa": "LA VIGA VIANA "
    },
    "choff": null
  },
  {
    "start": "2018-04-28T05:00:00.000Z",
    "fecha_asignacion": "2018-04-28 00:00:00",
    "termino_asignacion": null,
    "id_asignacion": 67,
    "id": 67,
    "idvehiculo": 1,
    "sucursal": 208,
    "empresa": 1,
    "idchofer": 1,
    "vehicul": {
      "id_vehiculo": 1,
      "placas": "YR-1779-5"
    },
    "sucursall": {
      "id_sucursal": 208,
      "n_suc": "Suc. Ticul"
    },
    "empresaa": {
      "id_empresa": 1,
      "n_empresa": "ARGENTUM MEXICANA S DE RL DE CV"
    },
    "choff": {
      "id_chofer": 1,
      "n_chofer": "JOSE AGUSTO PAT ONZALEZ"
    }
  }
]
}
$( function() {
//get elements from dom
  var txtData = document.getElementById('data');
  var data = JSON.parse(txtData.value);
  var btnLoad = document.getElementById('load');
  var btnSave = document.getElementById('save');
  // Create an empty DataSet.
  // This DataSet is used for two way data binding with the Timeline.
  var items = new vis.DataSet();

  // create a timeline
  var container = document.getElementById('visualization');

//options with template

var options = { editable:{

  add: false,         // add new items by double tapping
updateTime: true,  // drag items horizontally
updateGroup: true, // drag items from one group to another
remove: false,       // delete an item by tapping the delete button top right
overrideItems: false  // allow these options to override item.editable

},

  // create a template manualy, data is a json load from textarea, same like documentation

template: function (item, element, data) {

var empr=""; if ($.trim(data.empresaa)) { empr=data.empresaa.n_empresa; }; var sucr=""; if ($.trim(data.sucursall)){ sucr=data.sucursall.n_suc;} var chf=""; if ( $.trim(data.choff)) {chf=data.choff.n_chofer;}

html=

                    "<div class='vis-editable'>"+
                      "<p>"+empr+"</p>"+
                  '<p><small class="text-muted"><i class="glyphicon glyphicon-time"> 
               </i>'+data.fecha_asignacion+'-'+data.termino_asignacion+'</small></p>'+
                  "<table style='text-align: left;'>"+
             " <tr>"+

              "<td>Chofer:</td><td>"+chf+"</td>"+
              "</tr>"+
              "<tr>"+
              "<td>Sucursal:</td><td>"+sucr+"</td>"+
                "</tr>"+
                "<tr>"+
                "<td>Empresa:</td><td>"+empr+"</td>"+
                    "</tr>"+
                   "<tr>"+
                          "<td>Estado:</td><td>Activo</td>"+
                      "</tr>"+
                         "</table></div>";

return html;

},

// onMoving: function (item, callback) { // item.moving = true; // } };

var timeline = new vis.Timeline(container, items, options); // console.log("console log4 desoyes de crear el time line"); loadData(); function loadData () { // get and deserialize the data txtData = document.getElementById('data');

data = JSON.parse(txtData.value); /// console.log("log de load",data);

for(var k in data) { // console.log(k,data[k]);

for(var d in data[k]) {

// console.log(d,data[k][d]);

if (d=="fecha_asignacion") { // console.log("entre a cambiar el formato",data[k][d]); var spt= data[k][d]; var car=spt.split("-",3); // console.log("resultado: ",car[0],car[1],car[2]); data[k]["start"]= new Date(""+car[0]+"/"+car[1]+"/"+car[2]+""); // data[k]["start"]= new Date(car[0],car[1],car[2],0,0,0); // console.log(k,d,"quepedo2", data[k]["start"]); }

} }

/// items.clear(); // console.log("que pedo",data); items.add(data);

// console.log("se agrego a items data");

timeline.fit();

  // console.log("se termino timeline.fit");

} btnLoad.onclick = loadData;

function saveData() {

var data = items.get({
  type: {
    start: 'ISODate',
    // end: 'ISODate'
  }
});

txtData.value = JSON.stringify(data, null, 2);

} // console.log("log6 fase final"); btnSave.onclick = saveData;

// load the initial data loadData();

});

       ```
KalasinSeymour commented 6 years ago

It would be really nice if you could recreate your issue on jsbin or jsfiddle. If that's not possible could you at least edit your code in a way that all of it is shown in code style, not only parts of it? In it's current form it is really hard to read. :)