Load data in a footable javaScript

0

Friends I am having the following inconvenience, I try to load the data in a footable, I try to do it in the following way and it does not work for me:

 $("#status").change(function () {
                var respuesta=new String();
                respuesta= "[{'id':'5629499534213120','Email':'[email protected]', 'cuenta':'fislatec', 'Nombre':'andres alba','Perfil':'Administrador', 'Estado':'Estados','Action':'Botones'}]";
                $("#tUsuarios").footable({
                                        "sorting": {
                                            "enabled": true
                                        },
                                        "toggleSelector": ".footable-toggle",
                                        "columns": [
                                            {"name": "Nombre", "title": "Nombre"},
                                            {"name": "id", "title": "id", "visible": false},
                                            {"name": "Email", "title": "Email"},
                                            {"name": "cuenta", "title": "cuenta", "visible": false},
                                            {"name": "Perfil", "title": "Perfil"},
                                            {"name": "Estado", "title": "Estado"},
                                            {"name": "Action", "title": "Acción"}
                                        ],
                                        'rows':respuesta
                                    });
                        });

But this way if it works for me:

  $("#status").change(function () {


                $("#tUsuarios").footable({
                                        "sorting": {
                                            "enabled": true
                                        },
                                        "toggleSelector": ".footable-toggle",
                                        "columns": [
                                            {"name": "Nombre", "title": "Nombre"},
                                            {"name": "id", "title": "id", "visible": false},
                                            {"name": "Email", "title": "Email"},
                                            {"name": "cuenta", "title": "cuenta", "visible": false},
                                            {"name": "Perfil", "title": "Perfil"},
                                            {"name": "Estado", "title": "Estado"},
                                            {"name": "Action", "title": "Acción"}
                                        ],
                                        'rows':[{'id':'5629499534213120','Email':'[email protected]', 'cuenta':'fislatec', 'Nombre':'andres alba','Perfil':'Administrador', 'Estado':'Estados','Action':'Botones'}]
                                    });
                        });
    
asked by afar1793 25.01.2018 в 17:00
source

3 answers

0

In the first example to 'rows' you assign a string, while in the second example an array of objects.

If the data you want to use comes in that format you may need to use JSON.parse () to transform them into valid javascript objects.

    
answered by 25.01.2018 в 17:09
0

The first one is sending a single string, while in the second you send an array of objects. Just adjust the data types.

 $("#status").change(function () {
                var respuesta= [{'id':'5629499534213120','Email':'[email protected]', 'cuenta':'fislatec', 'Nombre':'andres alba','Perfil':'Administrador', 'Estado':'Estados','Action':'Botones'}];
                $("#tUsuarios").footable({
                                        "sorting": {
                                            "enabled": true
                                        },
                                        "toggleSelector": ".footable-toggle",
                                        "columns": [
                                            {"name": "Nombre", "title": "Nombre"},
                                            {"name": "id", "title": "id", "visible": false},
                                            {"name": "Email", "title": "Email"},
                                            {"name": "cuenta", "title": "cuenta", "visible": false},
                                            {"name": "Perfil", "title": "Perfil"},
                                            {"name": "Estado", "title": "Estado"},
                                            {"name": "Action", "title": "Acción"}
                                        ],
                                        'rows':respuesta
                                    });
                        });
    
answered by 25.01.2018 в 17:10
0

What your colleagues said, try this:

var respuesta = '[{"id":"5629499534213120","Email":"[email protected]", "cuenta":"fislatec", "Nombre":"andres alba","Perfil":"Administrador", "Estado":"Estados","Action":"Botones"}]';
respuesta = JSON.parse(respuesta);
    
answered by 25.01.2018 в 18:40