{"action":"created","issue":{"url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/1190","repository_url":"https://api.github.com/repos/Laravel-Backpack/CRUD","labels_url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/1190/labels{/name}","comments_url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/1190/comments","events_url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/1190/events","html_url":"https://github.com/Laravel-Backpack/CRUD/issues/1190","id":288883732,"number":1190,"title":"Move DataTable settings to PHP","user":{"login":"aripekkako","id":22023038,"avatar_url":"https://avatars0.githubusercontent.com/u/22023038?v=4","gravatar_id":"","url":"https://api.github.com/users/aripekkako","html_url":"https://github.com/aripekkako","followers_url":"https://api.github.com/users/aripekkako/followers","following_url":"https://api.github.com/users/aripekkako/following{/other_user}","gists_url":"https://api.github.com/users/aripekkako/gists{/gist_id}","starred_url":"https://api.github.com/users/aripekkako/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aripekkako/subscriptions","organizations_url":"https://api.github.com/users/aripekkako/orgs","repos_url":"https://api.github.com/users/aripekkako/repos","events_url":"https://api.github.com/users/aripekkako/events{/privacy}","received_events_url":"https://api.github.com/users/aripekkako/received_events","type":"User","site_admin":false},"labels":[{"id":752341145,"url":"https://api.github.com/repos/Laravel-Backpack/CRUD/labels/Feature%20Request","name":"Feature Request","color":"d8f79b","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-01-16T12:06:03Z","updated_at":"2018-02-13T12:44:35Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nthis is a feature proposal. \r\n\r\nI propose that the DataTable settings in <https://github.com/Laravel-Backpack/CRUD/blob/master/src/resources/views/list.blade.php#L145> would be moved to a method of the CRUD class. E.g. a method called `getDataTableOptions()` that returns a simple array that will be json encoded in the view. \r\n\r\nThis would add a lot of flexibility to editing the list views as the configuration would not be hardcoded in the list view but could be easily overridden by the inheriting CRUD class.\r\n\r\nI think keeping the configuration within PHP for JavaScript libraries in general is a much better convention than hardcoding it into the blade views.\r\n"},"comment":{"url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/comments/365256154","html_url":"https://github.com/Laravel-Backpack/CRUD/issues/1190#issuecomment-365256154","issue_url":"https://api.github.com/repos/Laravel-Backpack/CRUD/issues/1190","id":365256154,"user":{"login":"aripekkako","id":22023038,"avatar_url":"https://avatars0.githubusercontent.com/u/22023038?v=4","gravatar_id":"","url":"https://api.github.com/users/aripekkako","html_url":"https://github.com/aripekkako","followers_url":"https://api.github.com/users/aripekkako/followers","following_url":"https://api.github.com/users/aripekkako/following{/other_user}","gists_url":"https://api.github.com/users/aripekkako/gists{/gist_id}","starred_url":"https://api.github.com/users/aripekkako/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aripekkako/subscriptions","organizations_url":"https://api.github.com/users/aripekkako/orgs","repos_url":"https://api.github.com/users/aripekkako/repos","events_url":"https://api.github.com/users/aripekkako/events{/privacy}","received_events_url":"https://api.github.com/users/aripekkako/received_events","type":"User","site_admin":false},"created_at":"2018-02-13T12:44:35Z","updated_at":"2018-02-13T12:44:35Z","author_association":"NONE","body":"For most JS plugins the configuration is just plain JSON, so I was thinking about something like this:\r\n\r\n### CrudController \r\n\r\n```\r\n public function getDataTableConfiguration()\r\n    {\r\n        $dataTableConfiguration = [\r\n            \"pageLength\" =>  $this->crud->getDefaultPageLength(),\r\n            \"lengthMenu\" =>  [[10, 25, 50, 100, -1], [10, 25, 50, 100, trans('backpack::crud.all')]],\r\n            /* Disable initial sort */\r\n            \"aaSorting\" =>  [],\r\n            \"language\" =>  [\r\n                \"emptyTable\" =>      trans('backpack::crud.emptyTable'),\r\n                \"info\" =>            trans('backpack::crud.info'),\r\n                \"infoEmpty\" =>       trans('backpack::crud.infoEmpty'),\r\n                \"infoFiltered\" =>    trans('backpack::crud.infoFiltered'),\r\n                \"infoPostFix\" =>     trans('backpack::crud.infoPostFix'),\r\n                \"thousands\" =>       trans('backpack::crud.thousands'),\r\n                \"lengthMenu\" =>      trans('backpack::crud.lengthMenu'),\r\n                \"loadingRecords\" =>  trans('backpack::crud.loadingRecords'),\r\n                \"processing\" =>      \"<img src=\" . asset('vendor/backpack/crud/img/ajax-loader.gif') . \"' alt='\" . trans('backpack::crud.processing'). \"'>\",\r\n                \"search\" =>          trans('backpack::crud.search'),\r\n                \"zeroRecords\" =>     trans('backpack::crud.zeroRecords'),\r\n                \"paginate\" =>  [\r\n                    \"first\" =>       trans('backpack::crud.paginate.first'),\r\n                    \"last\" =>        trans('backpack::crud.paginate.last'),\r\n                    \"next\" =>        trans('backpack::crud.paginate.next'),\r\n                    \"previous\" =>    trans('backpack::crud.paginate.previous')\r\n                ],\r\n                \"aria\" =>  [\r\n                    \"sortAscending\" =>   trans('backpack::crud.aria.sortAscending'),\r\n                    \"sortDescending\" =>  trans('backpack::crud.aria.sortDescending')\r\n                ],\r\n                \"buttons\" =>  [\r\n                    \"copy\" =>    trans('backpack::crud.export.copy'),\r\n                    \"excel\" =>   trans('backpack::crud.export.excel'),\r\n                    \"csv\" =>     trans('backpack::crud.export.csv'),\r\n                    \"pdf\" =>     trans('backpack::crud.export.pdf'),\r\n                    \"print\" =>   trans('backpack::crud.export.print'),\r\n                    \"colvis\" =>  trans('backpack::crud.export.column_visibility')\r\n                ],\r\n            ],\r\n            \"processing\" =>  true,\r\n            \"serverSide\" =>  true,\r\n            \"ajax\" =>  [\r\n                \"url\" =>  url($this->crud->route.'/search') . '?'. Request::getQueryString(),\r\n                \"type\" =>  \"POST\"\r\n            ]\r\n        ];\r\n\r\n        if ($this->crud->exportButtons()) {\r\n            // show the export datatable buttons\r\n            $dataTableConfiguration['dom'] =\r\n                \"<'row'<'col-sm-6'l><'col-sm-6'f>>\" +\r\n                \"<'row'<'col-sm-12'tr>>\" +\r\n                \"<'row'<'col-sm-4'i><'col-sm-4'B><'col-sm-4'p>>\";\r\n            $dataTableConfiguration['buttons'] = $this->crud->dtButtons(['copyHtml5','excelHtml5','csvHtml5','pdfHtml5','print','colvis']);\r\n        }\r\n        return $dataTableConfiguration;\r\n    }\r\n```\r\n\r\n### Blade\r\n\r\n```\r\nvar table = $(\"#crudTable\").DataTable({{json_encode($this->getDataTableConfiguration())}});\r\n```\r\n\r\nThe idea is to simply create the object fully in PHP and then use json_encode to pass it to JS script. This would require you to rewrite the \"dtButtons\" JS-implemention in PHP.\r\n\r\nI understand that this can already be achieved by using a custom blade template, but having your own blade template for each small change that you might have seems like an overkill. E.g. disabling an export button, or disabling \"table\" button in a WYSIWYG editor. With this approach you could simply override the CrudController method, execute `parent::getDataTableConfiguration`, edit some keys and return it. Most Backpack version upgrades would also work flawlessly.\r\n\r\nIf your approach is to always override the blade templates that is okay, very flexible and \"laravelly\". However, if there already is a dependency to the CrudController in the blade template (such as \"$crud->exportButtons()\") I would argue that this kind of an approach would be more holistic, coherent and easier to maintain (just create PHP objects instead of somehow combining them in the templates). All configuration is kept in the Controller and can be modified and overridden from there."}}
{"actor":{"display_login":"aripekkako"}}