Editor with Laravel

Editor with Laravel

lunguc@hotmail.comlunguc@hotmail.com Posts: 20Questions: 6Answers: 0

Hi,
I have bought the editor 1.4.2 and I want to integrate it in Laravel. I'm working with Datatable.net. Is there any manual to point me how to do that?

Thanks.

Answers

  • allanallan Posts: 63,235Questions: 1Answers: 10,417 Site admin

    Hi,

    Editor's client / server communication protocol is documented in the manual here. Using it with Laravel you would need to either implement a suitable server-side environment for those requirements, or use the pre-built Editor PHP libraries alongside your Laravel code.

    Regards,
    Allan

  • lunguc@hotmail.comlunguc@hotmail.com Posts: 20Questions: 6Answers: 0
    edited April 2015

    Hi Allan,
    I'm not able to use de editor. I only want to use the client side with my controller (server side).
    I already have populate the datatable and I want to call the inline editor and next I want to submit the form. After, my controller will validate the data and save it the database.
    When I try to call the editor I receive an error: "Uncaught Unable to automatically determine field from source. Please specify the field name"
    I put my code to take a look, maybe you can help me.
    Thanks.

    @extends('layouts.master')
    
    @section('head_scripts')
        <!-- DataTables CSS -->
        {{ HTML::style('css/plugins/dataTables.bootstrap.css') }}
    @stop
    
    @section('title')
        <p>Incasari factura
            @if(isset($factura->serie)) {{ $factura->serie . '/' . $factura->numar }} din data {{ $factura->data_facturare }} @endif
        </p> 
    @stop
    
    @section('content')
        <div class="row">
            <div class="col-lg-12">
               <div class="panel panel-primary">
                    <div class="panel-heading">Zona de cautare
                        <button id="btn_show_hide" class="btn btn-primary" title="Afiseaza / Ascunde zona de cautare">
                            <i class="fa fa-list"></i>
                        </button>  
                    </div>                                                                                          
                </div>        
                <div class="panel panel-default">
                   <div class="panel-heading">
                        Incasari asociate facturii curente
                        <div class="pull-right">                      
                            <a href="{{ URL::previous() }}"><i class="fa fa-arrow-circle-left fa-fw"></i> Inapoi</a>                      
                            <a href="{{ URL::to('entitati_publice/add') }}"><i class="fa fa-plus-circle fa-fw"></i> Nou</a>                      
                        </div>
                   </div>
                   <div class="panel-body">
                       <div class="table-responsive">
                          <table class="table table-striped table-bordered table-hover" id="dataTables-incasari">
                            <thead>
                              <tr>                                   
                                <th class="text-center">Data incasarii</th>                      
                                <th class="text-center">Valoare incasata</th>
                                <th class="text-center">Valoare virata in contul de garantie</th>
                              </tr>
                            </thead>
                            <tfoot>
                              <tr>                                                               
                                <th class="text-center">Data incasarii</th>                      
                                <th class="text-center">Valoare incasata</th>
                                <th class="text-center">Valoare virata in contul de garantie</th>
                              </tr>
                            </tfoot>
                            <tbody>                             
                              @foreach ($incasari as $incasare)
                                <tr data-id="{{ $incasare->id_incasare }}">                              
                                  <td class="text-center">{{ $incasare->data_incasarii }}</td>                            
                                  <td class="text-right">{{ number_format($incasare->valoare_incasata, 2, ',', '.') }}</td>
                                  <td class="text-right">{{ number_format($incasare->valoare_virata_CG, 2, ',', '.') }}</td>                               
                                </tr>
                              @endforeach                             
                            </tbody>
                          </table>
                       </div>
                       <!-- /.table-responsive -->
                   </div>
                   <!-- /.panel-body -->
               </div>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row --> 
    @stop
    
    @section('footer_scripts')
        <!-- DataTables JavaScript -->
        {{ HTML::script('js/plugins/dataTables/jquery.dataTables.js') }}
        {{ HTML::script('js/plugins/dataTables/dataTables.bootstrap.js') }}
        {{ HTML::script('js/plugins/dataTables/dataTables.tableTools.js') }}
        {{ HTML::script('js/plugins/dataTables/jquery.dataTables.columnFilter.js') }}
        {{ HTML::script('js/plugins/bootbox.js') }}     
        {{ HTML::script('Editor-PHP-1.4.2/js/dataTables.editor.js') }}
    
        <script>
            var editor;        
     
            $(document).ready(function() {    
                $('#dataTables-incasari').dataTable({
                    "aoColumnDefs": [
                        { 'bSortable': false, 'aTargets': [ 0, 1 ] }
                    ],
                    "language": {                
                        "url": '{{ URL::to("js/plugins/dataTables/lang_json/romanian.json") }}'}
                });
    
                var table = $('#dataTables-incasari').dataTable().columnFilter({
                  aoColumns: [ 
                      { sSelector: "#_col_data_incasarii", type: "text" },
                      { sSelector: "#_col_valoare_incasata", type: "text" },
                      { sSelector: "#_col_valoare_virata_cont_garantie", type: "text" },                
                    ]
                }); 
    
                editor = new $.fn.dataTable.Editor( {
                    ajax: "../php/staff.php",
                    table: "#dataTables-incasari",
                    fields: [{
                            label: "First name:",
                            name: "_col_data_incasarii"
                        }, {
                            label: "Last name:",
                            name: "_col_valoare_incasata"
                        }, {
                            label: "Position:",
                            name: "_col_valoare_virata_cont_garantie"
                        }]
                });
    
                $('#dataTables-incasari').on( 'click', 'tbody td:not(:first-child)', function (e) {
                  editor.inline( this );
                });                      
            });
    
            $(function() {
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-Token': $('meta[name="_token"]').attr('content')
                    }
                });
            });
        </script>
    @stop
    
  • allanallan Posts: 63,235Questions: 1Answers: 10,417 Site admin

    This tech note explains what is causing the error and how to resolve it.

    In this case the problem is being caused by the fact that you have fields.name set to a string, but the DataTable is using a default of an integer for each column's data since there is no columns.data property specified.

    Using the editField option can resolve that, or use fields.data as an integer.

    Allan

This discussion has been closed.