Laravel 4.2中的EditorTable Pivot视图

时间:2016-04-05 12:53:57

标签: php laravel

我正在使用Laravel应用程序,该应用程序碰巧使用了EditorTable(来自http://editor.datatables.net/的表格的表兄弟)。我可以通过get和post让表格正常工作,但是我需要使用我的SQL DB设置,我需要使编辑器动态化。基本上我有一个表,其中包含课程代码和学期年度以及最终用户将在每年年底插入的指标响应。

如何使编码动态化?有时,一个课程可能有5个指标要显示,而另一个可能在我的数据库中有15个。 (而不是让我的SQL表保持静态,我把它变成了一个简单的收集器,因为类不同。我在考虑每个循环,但我可以在这里使用一些帮助。编码如下:

var table = $('#example').DataTable( {
                                        // Makes one continuous line - jsg 2/12/2016
            "scrollX": true,

            "autoWidth": false,
                                        // How many rows to return - jsg 2/16/2016
                "pageLength": 25,
                                        // Setup the search box with the current username to filter the values on the screen - jsg 2/12/2016
                "search": {search: '<?php echo $auth_id;?>' + ' INQ 300 '   },
                                        // End Search Setup populate
                dom: "Bfrtip",
               ajax: "../app/controllers/INQControllers.php"
                columns: [
                    {
                        data: null,
                        defaultContent: '',
                        className: 'select-checkbox',
                        orderable: false
                    },
                    { data: "fkey_instructor1_rcid", visible: false },
                    { data: "first_name" },
                    { data: "last_name" },
                    { data: "fkey_course_id" },
                    { data: "course_code"  },
                    { data: "course_number" },
                    { data: "course_section" },
              { data: "fkey_semester_id"},
              { data: "category"},
              { data: "Metric_text"},
              { data: "response_value"}

                ],

                order: [ 1, 'asc' ],
                keys: {
                    columns: ':not(:first-child)',
                    keys: [ 9 ]
                },
                select: {
                    style:    'os',
                    selector: 'td:first-child'
                },
                buttons: [

                    { extend: "edit",   editor: editor },
              {
                  extend: 'collection',
                  text: 'Export',
                  buttons: [
                      'copy',
                      'excel',
                      'csv',
                      'pdf',
                      'print'
                  ]
              }
                    //{ extend: "remove", editor: editor }
                ]
            } );
               // Activate an inline edit on click of a table cell
            $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
                editor.inline( this );
            } );

            // Inline editing on tab focus
             table.on( 'key-focus', function ( e, datatable, cell ) {
                 editor.inline( cell.index(), {
                     onBlur: 'submit'
                 } );
                          } );



            } );

我希望在可能的情况下让它变得动态:

columns: [
                        {
                            data: null,
                            defaultContent: '',
                            className: 'select-checkbox',
                            orderable: false
                        },
                        { data: "fkey_instructor1_rcid", visible: false },
                        { data: "first_name" },
                        { data: "last_name" },
                        { data: "fkey_course_id" },
                        { data: "course_code"  },
                        { data: "course_number" },
                        { data: "course_section" },
                  { data: "fkey_semester_id"},
                  { data: "category"},
                  { data: "Metric_text"},
                  { data: "response_value"}

表标题:

<table id="example" class="display" cellspacing="0" width="100%">
                                <thead>
                                    <tr>
                                        <th></th>
                            <th>Instructor</th>
                                    <th>First Name</th>
                                        <th>Last Name</th>
                                          <th>Course ID</th>
                                <th>Code</th>
                                <th>Number</th>
                                <th>Section</th>
                              <th>Sesmenter</th>
                              <th>Category</th>
                              <th>Metric Text</th>
                              <th width="3%">Metric Value</th>
                                    </tr>
                        </table>
                                </thead>

我的Ajax电话:

Editor::inst( $db, 'gen_ed_assessment.responses_data_record')
    ->fields(
        Field::inst( 'fkey_instructor1_rcid' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'category' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'Metric_text' ),

        Field::inst( 'response_value' )
                 ->validator( 'Validate::values',  array('valid' => array("0.0","0.5","1.0","1.5", "2.0", "2.5","3.0", "3.5", "4.0"))),

        Field::inst( 'fkey_course_id' ),
        Field::inst( 'id' ),
        Field::inst( 'first_name' ),
        Field::inst( 'last_name' ),
        Field::inst( 'fkey_semester_id' ),
        Field::inst( 'course_code' ),
        Field::inst( 'course_number' ),
        Field::inst( 'course_section' )

最后,这不是我作为数据库管理员为大学工作的家庭作业,而且我正在使用php和laravel进行前端编码。

1 个答案:

答案 0 :(得分:0)

好的,所以我想出了如何让它变得动态,而不仅仅是EditorTable,因为它只是使数据转向。在Laravel 4.2中,我能够在刀片中创建一个轴,然后使其可编辑。

foo(int i) { return foo(1d); /*it will call foo(double i)*/ }
foo(int i) { return foo(1); /*recursive call*/ }
相关问题