Maintaining unique primary key for every row when creating and editing

Maintaining unique primary key for every row when creating and editing

namastenamaste Posts: 1Questions: 1Answers: 0

I want to map the id-key from the database called 'videoarchives' to the DataTables-id called DT_RowId. When a new row is created I want it to use a unique primary key, and when it is edited to maintain this unique primary key.

I would like to know how I should modify the code in videos.php below in order to accomplish this. I found this example in the documentation, using another syntax. How can I adapt the code below to accomplish the same thing? ( http://www.datatables.net/examples/server_side/ids.html ):

// Array of database columns which should be read and sent back to DataTables. // The db parameter represents the column name in the database, while the dt // parameter represents the DataTables column identifier - in this case object // parameter names

$columns = array(
array(
'db' => 'id',
'dt' => 'DT_RowId',
'formatter' => function( $d, $row ) {
// Technically a DOM id cannot start with an integer, so we prefix
// a string. This can also be useful if you have multiple tables
// to ensure that the id is unique with a different prefix
return 'row_'.$d;
}
),
Some of the code from videoadmin.html:

$(document).ready(function() { //fields we can add or edit ?
editor = new $.fn.dataTable.Editor( {
ajax: "../php/videos.php",
table: "#example",
idSrc: "DT_RowId",
fields: [

        {
            label: "Title:",
            name: "videoarchives.Title"
        }, {
            label: "Date:",
            name: "videoarchives.Date",
            type: "date"
        }, {
            label: "VideoDescription:",
            name: "videoarchives.VideoDescription"
        }, {
            label: "Language:",
            name: "videoarchives.Language"
        }, {
            label: "Category:",
            name: "videoarchives.Category"
        }, {
            label: "VideoLink:",
            name: "videoarchives.VideoLink",

        }, {
            label: "HDLink:",
            name: "videoarchives.HDLink"
        },
        {
        label: "German title:",
        name: "videoarchives_german.TitleGerman"
        },
        {
        label: "German subtitle:",
        name: "videoarchives_german.SubtitleGerman"
        },
        {
        label: "German description:",
        name: "videoarchives_german.DescriptionGerman"
        }

    ]
} );

//oTable.fnSetColumnVis(0, false);
//http://stackoverflow.com/questions/15892995/assign-id-to-datatable-row-from-json-data
var dataTable = $('#example').DataTable( {
    dom: "Tfrtip",
    ajax: "../php/videos.php",

    columns: [

        { data: "DT_RowId" },
        { data: "videoarchives.Title" },

        { data: "videoarchives.Date" },
        { data: "videoarchives.VideoDescription" },
        { data: "videoarchives.Language" },
        { data: "videoarchives.Category" },
        { data: "videoarchives.VideoLink" },
        { data: "videoarchives.HDLink" },
        { data: "videoarchives_german.TitleGerman" },
        { data: "videoarchives_german.SubtitleGerman" },
        { data:  "videoarchives_german.DescriptionGerman"} 

    ],
    tableTools: {
        sRowSelect: "os",
        aButtons: [
            { sExtends: "editor_create", editor: editor },
            { sExtends: "editor_edit",   editor: editor },
            { sExtends: "editor_remove", editor: editor }
        ]
    } //table Tools

} ); //end of init datatable...

dataTable.fnSetColumnVis(0, false)

/* Click event handler */
 $('#example tbody').on( 'click', 'tr', function () {
    if ( $(this).hasClass('selected') ) {
        $(this).removeClass('selected');
    }
    else {
        table.$('tr.selected').removeClass('selected');
        $(this).addClass('selected');
    }
} );

$('#button').click( function () {
    table.row('.selected').remove().draw( false );
} );

} );

I want to map the id-key from the database called 'videoarchives' to the DataTables-id called DT_RowId. When a new row is created I want it to use a unique primary key, and when it is edited to maintain this unique primary key.

I would like to know how I should modify the code in videos.php below in order to accomplish this. I found this example in the documentation, using another syntax. How can I adapt the code below to accomplish the same thing? ( http://www.datatables.net/examples/server_side/ids.html ):

// Array of database columns which should be read and sent back to DataTables. // The db parameter represents the column name in the database, while the dt // parameter represents the DataTables column identifier - in this case object // parameter names

The php-code: http://stackoverflow.com/questions/26234352/jquery-datatables-editor-maintaining-unique-primary-key-for-every-row

This discussion has been closed.