Editor data

Editor data

gmstephanegmstephane Posts: 11Questions: 5Answers: 0

Hello,
I am using editor. i would like to insert a link on a specific column . the link should avec the id of the row data.
witch file in editor should i modify. Here is the html code

<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="suiviprojet" width="100%">
                <thead>
                    <tr>
                        <th>intitule du Projet</th>
                        <th>objet du Projet</th>
                        <th>date début</th>
                        <th>date fin</th>
                        <th>Composantes</th>
                        <th>resultats attendus</th>
                        <th>Cout Projet</th>
                        <th>devise</th>
                        <th>personeRessource</th>
                    </tr>
                </thead>
            </table>

The php code:

<?php

/*
 * Editor server script for DB table suiviprojet
 * Created by http://editor.datatables.net/generator
 */

// DataTables PHP library and database connection
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// The following statement can be removed after the first run (i.e. the database
// table has been created). It is a good idea to do this to help improve
// performance.
/*$db->sql( "CREATE TABLE IF NOT EXISTS `suiviprojet_admin` (
    `idProjet` int(10) NOT NULL auto_increment,
    `intituleprojet` varchar(255),
    `objetprojet` text,
    `datedebut` date,
    `datefin` date,
    `composantes` text,
    `resultatsattendus` text,
    `coutprojet` numeric(9,2),
    `devise` varchar(255),
    `personeressource` varchar(255),
    `dateajout` datetime,
    PRIMARY KEY( `idProjet` )
);" );
*/
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'suiviprojet_admin', 'idProjet' )
    ->fields(
        Field::inst( 'intituleprojet' )
            ->validator( Validate::notEmpty() ),
        Field::inst( 'objetprojet' ),
        Field::inst( 'datedebut' )
            ->validator( Validate::notEmpty() )
            ->validator( Validate::dateFormat( 'D, j M y' ) )
            ->getFormatter( Format::dateSqlToFormat( 'D, j M y' ) )
            ->setFormatter( Format::dateFormatToSql( 'D, j M y' ) ),
        Field::inst( 'datefin' )
            ->validator( Validate::notEmpty() )
            ->validator( Validate::dateFormat( 'D, j M y' ) )
            ->getFormatter( Format::dateSqlToFormat( 'D, j M y' ) )
            ->setFormatter( Format::dateFormatToSql( 'D, j M y' ) ),
        Field::inst( 'composantes' ),
        Field::inst( 'resultatsattendus' ),
        Field::inst( 'coutprojet' )
            ->validator( Validate::notEmpty() ),
        Field::inst( 'devise' ),
        Field::inst( 'personeressource' )
            ->validator( Validate::notEmpty() ),
        Field::inst( 'dateajout' )
            ->validator( Validate::dateFormat( 'Y-m-d H:i:s' ) )
            ->getFormatter( Format::datetime( 'Y-m-d H:i:s', 'Y-m-d H:i:s' ) )
            ->setFormatter( Format::datetime( 'Y-m-d H:i:s', 'Y-m-d H:i:s' ) )
    )
    ->process( $_POST )
    ->json();

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,352Questions: 1Answers: 10,443 Site admin

    A custom rendering function on the client-side is typically the way to construct a link in a specific column based on the row's data.

    Which column do you want the link in and how should it be constructed (i.e. what are the component parts)?

    Allan

  • gmstephanegmstephane Posts: 11Questions: 5Answers: 0

    Hello Allan
    Thanks for your quick reply
    i want to add hyperlink on column intituleprojet
    The hyperlink should contain the id of the row, and should open in another page. here is an example of what i found with render function:

    columns: [
                {
                    "data": "intituleprojet",
                    "render": function ( data, type, row, meta ) {
                        return '<a href="autrepage.php?idprojet=' + row.idProjet + '">' + data + '</a>';
                    }
                },
    

    But it result to undefined value:

    .../autrepage.php?idprojet=undefined 
    
  • allanallan Posts: 63,352Questions: 1Answers: 10,443 Site admin
    Answer ✓

    Add:

            Field::inst( 'idProjet' )
                ->set(false),
    

    to your PHP fields. Editor doesn't include the primary key value by default in the data array. It does have it as DT_RowId, so you could potentially grab it from there (and strip the prefix), but I think an easier option is just to include the primary key value as it is in the data object.

    Allan

  • gmstephanegmstephane Posts: 11Questions: 5Answers: 0

    Super it works fine. I added the code as you mentionned. Thank you Mr. Allan!

    another:

    how can i get the variable of idProjet in .../autrepage.php?idprojet= , so to display data in the datatable editor.

  • gmstephanegmstephane Posts: 11Questions: 5Answers: 0

    Super it works fine. I added the code as you mentionned. Thank you Mr. Allan!

    another one:

    how can i get the value of idProjet from .../autrepage.php?idprojet= , so to display data in the datatable editor.

  • allanallan Posts: 63,352Questions: 1Answers: 10,443 Site admin

    You mean display the primary key in a field? You could do that with a readonly field, just setup like any other field.

    Allan

  • gmstephanegmstephane Posts: 11Questions: 5Answers: 0

    Not exactly
    There a 2 pages involve projet page and activity page:

    when a user click in one projet, the link should open the second page activity with related data of the project clicked in project page using the idProjet passed in the hyperlink

    So my question is how to dysplay the data in activity page related to the project clicked. normaly i would used ans sql like this:
    select * from activity_table where foreignKey_idProjet = idProjet.

    Hope it's clear

  • allanallan Posts: 63,352Questions: 1Answers: 10,443 Site admin

    Thanks for the clarification.

    I think you'd SQL approach would be the right way to do it. DataTables and Editor don't currently provide a way to show a specific "card" of data on a page by itself. That would be up to the app developer to implement.

    Allan

Sign In or Register to comment.