Add column Total
Add column Total
Cdya
Posts: 12Questions: 5Answers: 0
I got error here
Field::value( '(subjects.Exam1 + subjects.Exam2 + subjects.Exam3) as Total')
{ data: "subject.Total" },
<?php
/*
* Example PHP implementation used for the index.html example
*/
// DataTables PHP library
include( "../../php/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;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'subjects', 'SubID' )
->fields(
Field::inst( 'subjects.Name' )->validator( 'Validate::notEmpty' ),
Field::inst( 'subjects.Exam1' )
->validator( 'Validate::numeric' )
->setFormatter( 'Format::ifEmpty', null ),
Field::inst( 'subjects.Exam2' )
->validator( 'Validate::numeric' )
->setFormatter( 'Format::ifEmpty', null ),
Field::inst( 'subjects.Exam3' )
->validator( 'Validate::numeric' )
->setFormatter( 'Format::ifEmpty', null ),
Field::inst( 'subjects.C_ID' )
->options( Options::inst()
->table( 'classes' )
->value( 'CID' )
->label( 'Name' )
)
->validator( 'Validate::dbValues' ),
Field::inst( 'classes.Name' ),
Field::inst( 'subjects.ExamID' )
->options( Options::inst()
->table( 'exams' )
->value( 'ID' )
->label( 'Name' )
)
->validator( 'Validate::dbValues' ),
Field::inst( 'exams.Name' ),
Field::value( '(subjects.Exam1 + subjects.Exam2 + subjects.Exam3) as Total')
)
->leftJoin( 'classes', 'classes.CID', '=', 'subjects.C_ID' )
->leftJoin( 'exams', 'exams.ID', '=', 'subjects.ExamID' )
->where( 'subjects.ExamID', $_GET['exam'] )
->process( $_POST )
->json();
This discussion has been closed.
Answers
I'm afraid that the Editor PHP libraries do not currently support SQL functions or operations such as the one you are attempting there. That might change with 1.7, I'm still looking into it, but for the moment you would need to select each individually and then sum them with a renderer on the client-side.
Allan