Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Dateformat in Datagrid

    General Discussion
    4
    6
    452
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dsharma last edited by

      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

      1 Reply Last reply Reply Quote 0
      • J
        Jyoti last edited by Jyoti

        @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
        }
        ]);

        1 Reply Last reply Reply Quote 0
        • D
          dsharma last edited by

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

          1 Reply Last reply Reply Quote 0
          • S
            sebastian last edited by

            For anyone still struggling here is the solution

            
                        'wrapper' => function ($data) {   
                            return date('d.m.Y H:i:s');                   
                        },
            
            
            1 Reply Last reply Reply Quote -1
            • S
              sebastian last edited by

              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');   
              },
              
              
              
              1 Reply Last reply Reply Quote 0
              • J
                jigs123 last edited by

                This is worked for me

                $this->addColumn([
                    'index'         => 'created_at',
                    'label'         => 'Created At',
                    'type'          => 'datetime',
                    'searchable'    => false,
                    'sortable'      => true,
                    'filterable'    => true,
                    'closure'  => function ($row) {
                        return date_format(date_create($row->created_at), 'd-m-Y h:i:s');
                    }
                ]);
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post