Chumper / Datatable

This is a laravel 4 package for the server and client side of datatables at http://datatables.net/
https://github.com/Chumper/Datatable
388 stars 154 forks source link

custome columns and json settings #43

Closed umefarooq closed 10 years ago

umefarooq commented 10 years ago

nice package how can we add custom column in it, for example i have 2 column coming from database id, name and want to add third custom column, action which will has anchor edit.

some more other features i don't want to use script from your package just generate only json settings for datatables which i can use in my javascript

Chumper commented 10 years ago

just use the addColumns function as described in the docs:

->addColumn('name',function($model)
        {
            return $model->getPresenter()->yourProperty
        }
    )
umefarooq commented 10 years ago

this column name you are getting from relation, i want to link name with anchor tag in datatable, i have used codeigniter datatables and it has edit column option where you can edit existing column or add any new column not from database table to view in datatables. have look on this library https://github.com/IgnitedDatatables/Ignited-Datatables

Chumper commented 10 years ago

You can even return a html link or similar:

->addColumn('name',function($model)
        {
            return '<a href="{{ url('/') }}" ><span><i class="icon-home"></i></span> Home </a>';
        }
    )
Chumper commented 10 years ago

Did that work out or do you need additional information?

umefarooq commented 10 years ago

yes thanks its work for me and really simple i like most important thing is whole model is getting passed in it and i can take values i want. now i am playing with this package more adding some javascript in it. again thanks for the nice package.

umefarooq commented 10 years ago

hi how we can set column width in html with both engines, one more thing in package description you are using view in render method can give example of view code

Chumper commented 10 years ago

Just edit the HTML template.

You can find both views that are shipping with this package here: https://github.com/Chumper/Datatable/tree/master/src/views

MarlonEtiene commented 10 years ago

Sorry to revive this topic but I think my question will be right here.

If I need to return a value of one field of the result I pass to collection method in my HTML.

I'll try to give an example:

    $result = Atendimento::orderBy($sortby, $order)
        ->Join('cliente', 'atendimento.a_cliente_id', '=', 'cliente.c_id')
        ->leftJoin('telefones', 'cliente.c_id', '=', 'telefones.t_id_cliente')  
        ->leftJoin('usuario', 'a_corretor_id', '=', 'usuario.id')
        ->leftJoin('repiques_favoritos', 'a_id', '=', 'repf_id_atendimento')
        ->leftJoin('cliente_imovel', 'a_cliente_id', '=', 'imob_cliente_id')
        ->leftJoin('imob_imoveis', 'imob_imovel_id', '=', 'imovel_id')
        ->leftJoin('imovel', 'imob_imoveis.imovel_id', '=', 'imovel.imovel_codigo')
        ->groupBy('a_id')
        ->Select('a_id', 'a_updated_at', 'c_nome', 't_cod_area', 't_telefone', 'usuario.nome', 'imovel.imovel_nome', 'imovel.imovel_bairro', 
            DB::Raw('(SELECT COUNT(r_id_atendimento) FROM atendimento_repique WHERE r_id_atendimento = a_id ) AS Total'), 'c_id')
        ->whereRaw('(repf_tipo <> 3 OR repf_tipo is null)')->get();

        return Datatable::collection($result)
                ->showColumns('#', 'a_id', 'a_updated_at', 'c_nome', 't_cod_area', 't_telefone', 'usuario.nome', 'imovel.imovel_nome', 
                    'imovel.imovel_bairro', 'Total', 'c_id')

                ->addColumn('#','<input type=\'checkbox\' id=\'myCheckbox[]\' tag= ---> here I need the a_id field -->')

                ->searchColumns('a_id', 'a_updated_at', 'c_nome', 't_cod_area', 't_telefone', 'usuario.nome', 'imovel.imovel_nome', 
                    'imovel.imovel_bairro', 'Total', 'c_id')

                ->orderColumns('a_id', 'a_updated_at', 'c_nome', 't_cod_area', 't_telefone', 'usuario.nome', 'imovel.imovel_nome', 
                    'imovel.imovel_bairro', 'Total', 'c_id')
                ->make();

Can you help me?

Thank you!

umefarooq commented 10 years ago

its simple as in Chumper answer to create input you need to do following things

->addColumn('#',function($model){ return Form::checkbox('myCheckbox[]', $model->a_id); })

hope this will work for you

MarlonEtiene commented 10 years ago

Thanks its work!