[SOLVED] How do I specify a column of selected row as value for new record

[SOLVED] How do I specify a column of selected row as value for new record

mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5
edited March 2015 in Editor

I want to restrict user from using "New" button until they have select a row - the table has records joined from 2 tables.
I want user to select a row and then be able to click "New"
Then I want to pre-fill the column "Eid" with the same value of "Eid" on the selected row...

editor
    .create( true) // can be false if I can add record and refresh table
    .set( 'Eid', ****needs to be value from selected row of tAttendance.Eid** ' )
    .submit();

This question has an accepted answers - jump to answer

Answers

  • mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5

    I tried this to add a "New" button when row is selected but button does not appear
    http://caritasme.com/dtedit_Attendance1.php?Eid=1

    tableTools: {
     sRowSelect: "os",
     sSwfPath: "//cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf",
     "fnRowSelected": function ( nodes ) { aButtons: [{ sExtends: "editor_create", editor: editor }]},
     aButtons: [
         { sExtends: "editor_edit",   editor: editor },
         { sExtends: "editor_remove", editor: editor },
           {
             sExtends: "collection",
             sButtonText: "Save",
             sButtonClass: "save-collection",
             aButtons: [ 'copy', 'csv', 'xls', 'pdf' ]
           },
           'print'
     ]
    },
    
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited March 2015

    What I would suggest is that you create a new TableTools button that extends the select_single button type (i.e. sExtends: 'select_single'). Then use a custom fnClick method for the button to check if a row has been selected or not (this.fnGetSelected().length===1) and if so call create().

    The editor_create button probably isn't going to help you here, I would suggest ignoring it and creating your own (like how you have for the collection).

    Allan

  • mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5

    Wow, thanks, will get started trying that ...

  • mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5
    edited March 2015 Answer ✓

    Thank you!
    Code I get to next works just as you said! (in case anyone else is at novice level like me and can use this ..)

        { sExtends: 'editor_create',  editor: editor,
           sButtonText: "Add Attendance for Selected row",
           "fnClick": function ( nButton, oConfig, oFlash ) {
                if ( this.fnGetSelected().length===1) {
                // can now create using parent table key from 2nd column
            var Eidnew = table.cell('.selected', 1).data();
                editor
                    .create( false )
                    .set( 'tAttendance.Eid', Eidnew) 
                    .submit();
                }
           }        
       },
    
  • mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5
    edited March 2015

    solved... see above

This discussion has been closed.