Need to use where in select box

Need to use where in select box

XerKXerK Posts: 25Questions: 8Answers: 0
Field::inst( 'subjects_d.SubjectID' )
            ->options( Options::inst()
                ->table( 'subjects' )
                ->value( 'ID' )
                ->label( 'Name' )
                ->where( 'Type', 1 )
            )
            ->validator( 'Validate::dbValues' ),
        Field::inst( 'subjects.Name' ),

Why where not work in options

->where( 'Type', 1 )

Answers

  • 100a1100a1 Posts: 3Questions: 0Answers: 0

    you could put it in a function...

        ->where( function ($q) {
            $q->where( 'Type', 1, '=' );
        }
    
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Why where not work in options

    It should do. Are you getting any error messages back?

    Allan

  • XerKXerK Posts: 25Questions: 8Answers: 0

    yes get messages back

  • XerKXerK Posts: 25Questions: 8Answers: 0

    DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

  • XerKXerK Posts: 25Questions: 8Answers: 0

    This is my server code.

    <?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_d', 'SubID' )
        ->fields(
            Field::inst( 'subjects_d.SubID' )->set(false),
            Field::inst( 'subjects_d.Exam1' )
                ->validator( 'Validate::numeric' )
                ->setFormatter( 'Format::ifEmpty', null ),
            Field::inst( 'subjects_d.Exam2' )
                ->validator( 'Validate::numeric' )
                ->setFormatter( 'Format::ifEmpty', null ),
            Field::inst( 'subjects_d.Exam3' )
                ->validator( 'Validate::numeric' )
                ->setFormatter( 'Format::ifEmpty', null ),
            Field::inst( 'subjects_d.C_ID' )
                ->options( Options::inst()
                ->table( 'classes' )
                ->value( 'CID' )
                ->label( 'Name' )
                )
                ->validator( 'Validate::dbValues' ),
            Field::inst( 'classes.Name' ),
            Field::inst( 'subjects_d.SubjectID' )
                ->options( Options::inst()
                    ->table( 'subjects' )
                    ->value( 'ID' )
                    ->label( 'Name' )
                )
                ->validator( 'Validate::dbValues' ),
            Field::inst( 'subjects.Name' ),
            Field::inst( 'subjects_d.ExamID' )
                ->options( Options::inst()
                    ->table( 'exams' )
                    ->value( 'ID' )
                    ->label( 'Name' )
                )
                ->validator( 'Validate::dbValues' ),
            Field::inst( 'exams.Name' )
        )
        ->leftJoin( 'classes', 'classes.CID', '=', 'subjects_d.C_ID' ) 
        ->leftJoin( 'subjects', 'subjects.ID', '=', 'subjects_d.SubjectID' ) 
        ->leftJoin( 'exams', 'exams.ID', '=', 'subjects_d.ExamID' ) 
        ->where ('subjects_d.ExamID', $_GET['exam'])
        ->where ('subjects.Type', $_GET['status'])
        ->process( $_POST )
        ->json();
    
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Can you show me the data that is being sent back for the server please? If it isn't valid JSON there is a reasonable chance that it contains an error message. The link in the error message you are getting shows how to view the data sent back from the server.

    Allan

  • XerKXerK Posts: 25Questions: 8Answers: 0

    Javascript

    <script type="text/javascript" language="javascript" class="init">  
        var editor; // use a global for the submit and return data rendering in the examples
        
        $(document).ready(function() {
    
            editor = new $.fn.dataTable.Editor( {
                ajax: 
                {
                    url: "examples/php/subjects_d.php?exam=<?php echo $examid ?>&status=<?php echo $statusid ?>",
                    type: "POST",
                },
                table: "#example",
                fields: [ {
                        label: "<?php echo lang('subject') ?>:",
                        name: "subjects_d.SubjectID",
                        type: "select",
                        placeholder: "Select a subject" 
                    }, {
    
                        label: "<?php echo lang('class') ?>:",
                        name: "subjects_d.C_ID",
                        type: "select",
                        placeholder: "Select a class"
    
                    }, {
                        label: "<?php echo lang('exam') ?>:",
                        name: "subjects_d.ExamID",
                        type: "select",
                        placeholder: "Select a exam",
                        "default": <?php echo $examid ?>
                    },
                <?php foreach ($types as $key => $edittype) { ?>
                    {
                        label: "<?php echo $edittype['Name'] ?>:",
                        name: "subjects_d.Exam<?php echo $key+1 ?>",
    
                    },
                <?php } ?>
                ]
            } );
    
            var table = $('#example').DataTable( {
                responsive: true,
                dom: "Bfrtip",
                "order": [1 , 'asc'],
                "pageLength": 100,
                ajax: 
                {
                    url: "examples/php/subjects_d.php",
                    type: "GET",
                    data: { 
                        "exam": <?php echo $examid ?>,
                        "status": <?php echo $statusid ?>
                        },
                },
                ajaxUrl: "examples/php/subjects_d.php",
                columns: [
                    {
                        data: null,
                        defaultContent: '',
                        className: 'select-checkbox',
                        orderable: false,
                        "ordering": false
                    },
                    { data: "subjects_d.C_ID"},
                    { data: "subjects.Name" },
                    { data: "classes.Name", className: 'editable'},
                    <?php foreach ($types as $key => $showtype) { ?>
                    { data: "subjects_d.Exam<?php echo $key+1 ?>" },
                    <?php } ?>
                    
                ],
                    autoFill: {
                        columns: [<?php $numItems = count($types); $i = 0; foreach ($types as $key => $edittype) { ?><?php echo $key+4?><?php if ( ++$i === $numItems ) {echo "";} else { echo ',';}} ?>],
                        editor:  editor
                    },
                    keys: {
                        columns: [<?php $numItems = count($types); $i = 0; foreach ($types as $key => $edittype) { ?><?php echo $key+4?><?php if ( ++$i === $numItems ) {echo "";} else { echo ',';}} ?>],
                        editor:  editor,
                    },
                select: {
                    style:    'os',
                    selector: 'td:first-child',
                    blurable: true
                },
    
                 "columnDefs": [
                     {
                         'targets': [1],
                         'visible': false,
                         'searchable': false
                     },
    
                    "render": function ( data, type, row ) {
                        return (+row.subjects_d.Exam1 + +row.subjects_d.Exam2 + +row.subjects_d.Exam3);
                    },
                    
                        "targets": <?php  echo $typesCount+4 ?>   
                },
                ],
                buttons: [
                    { extend: "create", editor: editor },
                    { extend: "edit",   editor: editor },
                    { extend: "remove", editor: editor }
                ]
            } );
        } );
    </script>
    
  • XerKXerK Posts: 25Questions: 8Answers: 0

    ?

  • XerKXerK Posts: 25Questions: 8Answers: 0

    up

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    That still isn't the data that is being transferred from the server. How to view that data is described in the link that the error message contains: http://datatables.net/tn/1 .

    Allan

  • XerKXerK Posts: 25Questions: 8Answers: 0

    I comment on it but you didn't approve my comment

  • XerKXerK Posts: 25Questions: 8Answers: 0

    it Give me type = 1 in Network Google chrome

  • XerKXerK Posts: 25Questions: 8Answers: 0

    what is an error there ?!

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Could you post it again please? I've marked your account so it won't be flagged again.

This discussion has been closed.