Possible Bug in Editor-1.4.0-beta

Possible Bug in Editor-1.4.0-beta

GeorgeIoakGeorgeIoak Posts: 27Questions: 6Answers: 0

I've been trying the duplicate example and using several different methods to retrieve data from the selected row. I've placed alerts to check the code and everything appears to be OK but I try before.set( values) is always returning row 0 data when the form opens.

The code I've tried is:

oTableTools: {
            sRowSelect: "os",
//          "sSwfPath": "http://localhost/DataTables-1.10.4/extensions/TableTools/swf/copy_csv_xls_pdf.swf",

            sRowSelector: "td:first-child",
            aButtons: [
                { sExtends: "editor_create", "editor": editor },
                { sExtends: "editor_edit",   "editor": editor },
                { sExtends: "editor_remove", "editor": editor },
                { 
                    sExtends: "select_single", 
                    sButtonClass: "marginLeft",
                    sButtonText: "Register",
                    fnClick: function( nButton, oConfig ) {
//                      registerPerson
//                          .title( "Register for 2015" )
//                          .buttons( { label: "Save", fn: function() { this.submit(); } } )
//                          .edit( myTable.row( '.selected' ).node() );
//                          var oTT = $.fn.dataTable.TableTools.fnGetInstance( 'allrecords' );
//                          var sData = oTT.fnGetSelectedData();
                            var sData = this.fnGetSelectedData();
                            var sIndex = this.fnGetSelectedIndexes();
                            var sRow = sIndex[0];
//                          alert('selected row: ' + sRow);
                            var values = editor.edit( sData[sRow], false ).val();
//                          alert('selected row 0: ' + sData[0].Fname+' '+sData[0].Lname+' '+sData[0].email);
//                          alert('selected row sRow: ' + sData[sRow].Fname+' '+sData[sRow].Lname+' '+sData[sRow].email);
                        editor
                            .create( {
                            title: 'Register '+sData[0].Fname+' '+sData[0].Lname,
                            buttons: "Add Person",
                            focus: 1
                            } )
                            .set( values )
//                          var thisYear = editor.field( 'conf_year' );
//                          thisYear
                            .field ( 'conf_year' ).val ( '2015' );
                        editor.field( 'conf_year' ).disable();
                    }
                },
//              { sExtends: "xls"},
                {
                    sExtends: "collection",
                    sButtonText: "Save",
                    sButtonClass: "save-collection",
                    aButtons: [ 'copy', 'csv', 'xls', 'pdf' ]
                },
                'print'
            ]
        }

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin

    It looks like you are passing in a data object to edit() - but that can't be used to identify a row by DataTables, which is probably what is causing the issue here.

    I would suggest simply doing editor.edit( sRow, false ). The sRow variable is a row index (so if you are using Hungarian notation it should really be iRow...) which row() can use to identify a row.

    Allan

  • GeorgeIoakGeorgeIoak Posts: 27Questions: 6Answers: 0

    This code originated from your Duplicate example, https://datatables.net/blog/2014-07-25. I'm doing basically the same thing as that but I couldn't get it to set the values of the selected row.

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    Answer ✓

    In my example I pass in the table node (from fnGetSelected()) but above you are using a data object from fnGetSelectedData().

    There is a running example of the duplicate button which might be of some use available here.

    Allan

  • GeorgeIoakGeorgeIoak Posts: 27Questions: 6Answers: 0

    That was it. I guess I made the mistake of experimenting too much!

  • GeorgeIoakGeorgeIoak Posts: 27Questions: 6Answers: 0
    edited January 2015

    Just for reference for someone else here's what I did. sItems isn't really needed since you can grab the data out of sData but I failed initially to figure it out so I reverted to what I knew worked and later I'll debug it further.

    The next step is to customize the layout of the form so fields can be placed on 1 lines rather than 1 field per line.

                        fnClick: function( nButton, oConfig ) {
    //                      registerPerson
    //                          .title( "Register for 2015" )
    //                          .buttons( { label: "Save", fn: function() { this.submit(); } } )
    //                          .edit( myTable.row( '.selected' ).node() );
    //                          var oTT = $.fn.dataTable.TableTools.fnGetInstance( 'allrecords' );
    //                          var sData = oTT.fnGetSelectedData();
                                var sData = this.fnGetSelected();
                                var sItems = this.fnGetSelectedData();
                                var values = editor.edit( sData[0], false ).val();
    //                          alert('selected row sRow: ' + sItems[0].Fname+' '+sItems[0].Lname+' '+sItems[0].email);
                            editor
                                .create( {
                                title: 'Register '+sItems[0].Fname+' '+sItems[0].Lname,
                                buttons: "Add Person",
                                focus: 1
                                } )
                                .set( values )
                                .field ( 'conf_year' ).val ( '2015' );
                            editor.field( 'conf_year' ).disable();
                        }
    
This discussion has been closed.