In search box first row username get auto filled and search when reload or click on edit and delete

In search box first row username get auto filled and search when reload or click on edit and delete

Aarti SharmaAarti Sharma Posts: 8Questions: 5Answers: 0

When i reload on click on edit some data id filled into search box following is my code .please review.

`var editor;

$(document).ready(function() {
var x;

        editor = new $.fn.dataTable.Editor( {           
        "ajax": "manage_data.php",
        "table": "#view",
        "fields": [
            {
                "label": "Type",
                "name": "usergroups",
                "type": "select",
                "ipOpts": [
                    { "label": "Admin", "value": "ladmin" },
                   // { "label": "Editor", "value": "leditor" },
                    { "label": "User", "value": "luser" },
                    { "label": "Librarian", "value": "llib" },

                ]
            },
              {
                  "type": "readonly",
                "label": "Username",
                "name": "username"

            },

            {
                "label": "Password",
                "name": "Passphrase"

            },

              {
                "label": "Name",
                "name": "name"

            },
                 {

                 "label": "Email",
                 "name": "email"

             }
        ]
    } );


    // New record
    $('a.editor_create').on('click', function (e) {
        e.preventDefault();

       editor
            .title( 'Create new record' )
            .buttons( { "label": "Add", "fn": function () { editor.submit();
               } } )
            .create();

    } );
     // Edit record
    $('#view').on('click', 'a.editor_edit', function (e) {
        e.preventDefault();

       $("input[type=search]").val(null);
        editor
            .title( 'Edit record' )
            .buttons( { "label": "Update", "fn": function () { editor.submit()


            } } )
            .edit( $(this).closest('tr') );

    } );

    // Delete a record (without asking a user for confirmation for this example)
    $('#view').on('click', 'a.editor_remove', function (e) {
        e.preventDefault();

        editor
            .title( 'Delete record' )
            .message( 'Are you sure you wish to remove this record?' )
            .buttons( { "label": "Delete", "fn": function () { editor.submit()  } } )
            .remove( $(this).closest('tr') );
    } );


    // DataTables init
     var fa = 0;
   var table = $('#view').DataTable( {             
          "sdom": 'T<"clear"><"H"lr>t<"F"ip>',
            //"bAutoWidth": false,
            "bProcessing": true,                  
            "aLengthMenu": [[10, 50, 100, 500], [10, 50, 100, 500]],
            //"bPaginate": false,

             initComplete: function(){
  var api = this.api();
  $('#view_filter input')
      .off('.DT')
      .on('keyup.DT', function (e) {
          if (e.keyCode == 13) {
              api.search(this.value).draw();
          }
      });

},
ajax: {
url: "manage_data.php",
type: "POST"
},

            "columns": [


            {  "sClass": "center",
            "data": "username"

            },

            {    "sClass": "center",
                "data": "Passphrase"
            },
            {    "sClass": "center",
                "data": "email"
            },


            {
                "sClass": "center",
                "data": "name"
            },
            {
                "sClass": "center",
                 "mRender":function(data, type, full)
                {
                    if ( full.usergroups==='ladmin')
                    {
                        return 'Admin';
                    }
                     else if ( full.usergroups==='leditor')
                    {
                      return 'Editor';
                    }
                     else if ( full.usergroups==='llib')
                    {
                      return 'Librarian';
                    }
                     else if ( full.usergroups==='luser')
                    {
                      return 'User';
                    }

                }

            },



              {
                "bSearchable": false,
                "bSortable": false,
                "mRender":function(data, type, full)
                {
                    if (full.name.indexOf('Editor - B.C.')>-1)
                    {
                      return '<center><img src="images/pencil-grey.png" width="16">&nbsp&nbsp&nbsp<img src="images/delete2-grey.png" width="16"></a></center>';  
                    }
                     else
                    {

                      return '<center><a href="" class="editor_edit"><img src="images/pencil.png" width="16"></a>&nbsp&nbsp&nbsp<a href="" class="editor_remove"><img src="images/delete2.png" width="16"></a></center>';
                    }
                }

            }

            ]
        } );

} );`

Answers

This discussion has been closed.