0

Switch status not working for datatable : I have switches in html string have been checked and unchecked for the DB values. It is not working for the else part only the active/checked switch is shown but the unchecked witch status is not displayed... Please check my condition if it is wrong....ASAP.....Regards....

$.each(checkUser, function(index, act){
                                console.log(act.accountEnabled);
                                **if(act.accountEnabled){   
                                     enableDisable = " <input id='switch-user' name='switch-user' type='checkbox' checked data-size='mini' data-on-label='Enable' data-off-label='Disable'>";

                                } else{
                                    enableDisable = " <input id='switch-user' name='switch-user' type='checkbox' data-size='mini' data-on-label='Enable' data-off-label='Disable'>";**

                                }
                                console.log(enableDisable);
                            }); 

var userData = data.users;
        var dataSet = [];
        $.each(userData, function(index, user){
            dataSet.push([
                user.name,
                user.userId,
                user.creationTime,
                user.accountEnabled,
                user.roleName,
                userActions,
                enableDisable
            ]);
        });


        var oTable = $('table#user-datatable').dataTable( {
            "data": dataSet,
            "bFilter": false,
            "bLengthChange": false,
            "bPaginate": false,
            "bInfo": false,
            "columnDefs": [ 
                { "targets": 5, "orderable": false, "width": "180px" },
                {"targets": 6, "orderable": false, "width": "60px" }

            ],
            "tableTools": {
                "sRowSelect": "single"
            },
            "columns": [
                { "title": "Name" },
                { "title": "UserId" },
                { "title": "CreationTime"},
                { "title": "Account Enabled" },
                { "title": "Role" },
                { "title": "Action"},
                {"title" : "Enable/Disable"}
            ],
            "fnInitComplete" : function(settings, json){
                $("input#switch-user").bootstrapSwitch();
            }
        });
Siguza
  • 21,155
  • 6
  • 52
  • 89
Vicky Singh Gill
  • 323
  • 2
  • 8
  • 19
  • my console is showing correct string but switch state is not rendered by the page or data table..it is showing for only true condition..... – Vicky Singh Gill Jul 09 '15 at 12:00
  • when you are using plugins please put the official link of that plugin in your question so that others don't have to go and find what plugin you are using. – Cerlin Jul 09 '15 at 12:13
  • also its better if you could re produce the problem in a fiddle and share with us. – Cerlin Jul 09 '15 at 12:14
  • Thanks, Cerlin my issue was resolved as I am using jquery data table,bootstrap switch..my issue was where I am creating the column rows that is where i am pushing in to data set i have to check my condition there only. So, not the status is populating fine. – Vicky Singh Gill Jul 10 '15 at 15:59

1 Answers1

0
var userData = data.users;
        var dataSet = [];
        $.each(userData, function(index, user){
            if(user.accountEnabled){   
                                     enableDisable = " <input id='switch-user' name='switch-user' type='checkbox' checked data-size='mini' data-on-label='Enable' data-off-label='Disable'>";
                                } 
                                else{
                                    enableDisable = " <input id='switch-user' name='switch-user' type='checkbox' data-size='mini' data-on-label='Enable' data-off-label='Disable'>";**
                                }
            dataSet.push([
                user.name,
                user.userId,
                user.creationTime,
                user.accountEnabled,
                user.roleName,
                userActions,
                enableDisable
            ]);
        });
Vicky Singh Gill
  • 323
  • 2
  • 8
  • 19