Undefined index error when creating a new row, on page that filters for data

Undefined index error when creating a new row, on page that filters for data

dhDTforwebdhDTforweb Posts: 19Questions: 4Answers: 0

I'm using Datatables and Editor for an online database. You can see it here:
https://quiet-wildwood-42059.herokuapp.com/index.php/SubUnit/viewSubUnitOfEquipment/1

I am getting this error when I try to create a new row by using the 'new' button.

<p>Severity: Notice</p>
<p>Message:  Undefined index: myID</p>
<p>Filename: models/SubUnit_Model.php</p>
<p>Line Number: 68</p>

The SubUnit_Model.php function is below.
The function works to display the subunits for specific equipment.
If I comment out the line "->where( 'eqid', $post['myID'])", I can create new rows of subunits, but the subunits are no longer filtered for specific equipment.

public function getSubUnitsOfEquipment($post)
  {
    // Build our Editor instance and process the data coming from _POST
        // Use the Editor database class
        Editor::inst( $this->editorDb, 'subunit' ) // change table name
    ->fields(
        Field::inst( 'projectid' ),
        Field::inst( 'bldgid' ),
        Field::inst( 'eqid' ),
        Field::inst( 'subtype' ),
        Field::inst( 'id' ),
        Field::inst( 'subname' ),
        Field::inst( 'section' ),
        Field::inst( 'line_order' ),
        Field::inst( 'dataname' ),
        Field::inst( 'design' ),
        Field::inst( 'actual' )
    )
    ->where( 'eqid', $_POST['myID'])
        ->process( $post )
        ->json();    
    }

I'm using this code in my view to send the myID data through the Ajax call.

var editor; 
$(document).ready(function() {
var myID = <?php echo $id; ?>;
    var editor = new $.fn.dataTable.Editor( {
        ajax: '/index.php/Ajax/subUnitOfEquipment',
        table: '#subUnit',
        fields: [
            {
etc.
    var table = $('#subUnit').DataTable( {
        
        dom: 'Bfrtip',
        ajax: {
            url: '/index.php/Ajax/subUnitOfEquipment',
            type: "POST",
            data: {"myID" : myID}
        },
                order: [[3, 'asc'], [5, 'asc'], [6, 'asc']],
            rowGroup: {
                dataSrc: ["subtype", "subname", "section"]
            },
        columns: [
            {
                "data": "projectid",
                        //"visible": false
                       
            },
            {
                "data": "bldgid",
                        //"visible": false
            },
etc.

The Ajax call works, but the data: {"myID" : myID} is not sent when the 'new' button is used. How can I send this data through when a new row is created?
Thanks!

Answers

  • dhDTforwebdhDTforweb Posts: 19Questions: 4Answers: 0

    Ok I got it. I created a second editor instance for the row creation, and directed the buttons to call it. Now it works.

        var editor2 = new $.fn.dataTable.Editor( {
            ajax: '/index.php/Ajax/subUnit',
            table: '#subUnit',
            fields: [
                {
                    "label": "dataname:",
                    "name": "dataname"
                },
                {
                    "label": "design:",
                    "name": "design"
                },
                {
                    "label": "actual:",
                    "name": "actual"
                }
            ]
        } );
    
    

    and

            buttons: [
                'pdf',
                { extend: 'create', editor: editor2 },
                { extend: 'edit',   editor: editor2 },
                { extend: 'remove', editor: editor2 }
            ]
    
Sign In or Register to comment.