Recent Topics

Dateformat in Datagrid



  • Hello,

    I am trying to change dateformat from y-m-d to m-d-y in package but not getting success. Can you tell me how to change dateformat in datagrid. I have tried in query also but not worked

      $this->addColumn([
            'index' => 'created_at',
            'label' => trans('marketplace::app.admin.sellers.created-at'),
            'type' => 'datetime',
            'sortable' => true,
            'searchable' => false,
            'filterable' => true
        ]);
    

    Regards
    Deepak Sharma



  • @dsharma said in Dateformat in Datagrid:

    $this->addColumn([
    'index' => 'created_at',
    'label' => trans('marketplace::app.admin.sellers.created-at'),
    'type' => 'datetime',
    'sortable' => true,
    'searchable' => false,
    'filterable' => true
    ]);
    you can use predefined method i.e "wrapper" for more customize
    eg :

    $this->addColumn([
    'index' => 'created_at',
    'label' => trans('marketplace::app.admin.sellers.created-at'),
    'type' => 'datetime',
    'sortable' => true,
    'searchable' => false,
    'filterable' => true,
    'wrapper' -> function ($data) {
    //all the value which is passed from the datagrid
    return date(m-d-y);
    //you can modified here like this
    }
    ]);



  • Thanks jyoti but i have already tried that it is not accepting data in closure function



  • For anyone still struggling here is the solution

    
                'wrapper' => function ($data) {   
                    return date('d.m.Y H:i:s');                   
                },
    
    


  • For anyone still struggling with there here is the correct answer

    
    'wrapper' => function ($data) {
           return date_format(date_create($data->created_at), 'd.m.Y H:i');   
    },
    
    
    

Log in to reply