์ด ํ๋ฌ๊ทธ์ธ์ ์์ฃผ ์ค๋ซ๋์ ์ฌ์ฉํ์ต๋๋ค. ํ์ง๋ง ๋ฉฐ์น ํ์๋ ์๋๊ฐ ๋๋ ค์ง๋๋ค (์ ๋ง ๋๋ฆฝ๋๋ค). > 1K ๋ฐ์ดํฐ๋ฅผ ์ฟผ๋ฆฌํ๋ ค๊ณ ํฉ๋๋ค. ๋ฐ์ดํฐ๋ฅผ ํ์ํ๊ธฐ ์ํด ์ต์ 5 ์ด ์ด์ ๊ณ์๋ก๋๋ฉ๋๋ค. ํ์ด์ง ๋งค๊น์ ๋ณ๊ฒฝํ ๋๋ ๋ฐ์ํฉ๋๋ค.
public function getData()
{
$brands = Brand::select('id', 'name');
return Datatables::of($brands)
->addColumn('action', function ($brand) {
return '
<a href="/brands/' . $brand->id . '/edit" class="btn btn-xs btn-primary">
<i class="fa fa-pencil"></i> Edit
</a>
<a href="#" id="delete-button" data-id="' . $brand->id . '" class="btn btn-xs btn-danger">
<i class="fa fa-times"></i> Delete
</a>
';
})
->make(true);
}
๋์งํธ ์ค์ $ 10.
๋ฐ์ดํฐ๋ฒ ์ด์ค์ 1 ๊ฐ ์ด์์ lac ๋ ์ฝ๋๊ฐ์๋ ๋์ผํ ๋ฌธ์ ์ ์ง๋ฉด ํด ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๋ด ์ง๋ฌธ๊ณผ ์๋๋ฆฌ์ค๋ ์ฝ๊ฐ ๋ณต์กํฉ๋๋ค. ๋ด ํ ์ด๋ธ์๋ 3 ๊ฐ ์ด์์ ํ ์ด๋ธ์ ๋ฐ์ดํฐ๊ฐ ํ์๋ฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ฐ์ดํฐ๋ฅผ ํ ์ด๋ธ๋ก ๋ ๋๋งํ๊ธฐ ์ ์ ์ด ๊ฐ์ ํธ์งํ๊ณ ์์ต๋๋ค.
์ด๊ฒ์ ๋ด ๊ฒฌํด์ ์ฝ๋์ ๋๋ค.
/**
*
*
* function to return table view
*/
public function inbox_ticket_list() {
$table = \Datatable::table()
->addColumn(
"", Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at'))
->noScript();
return view('themes.default1.agent.helpdesk.ticket.inbox', compact('table'));
}
๋ด ๊ฒฌํด๋ก๋ Datatble JavaScript๋ฅผ๋ก๋ํ๊ธฐ ์ํด ์ฌ์ฉ์ ์ ์ ๋ธ๋ ์ด๋ ํ์ผ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
{!!$table->render('vendor.Chumper.template')!!}
{!! $table->script('vendor.Chumper.ticket-javascript') !!}
๋ด JavaScript ๋ธ๋ ์ด๋ ํ์ผ์์ ์กฐ์ธ์ ์ฌ์ฉํ์ฌ ํ
์ด๋ธ์ ๋ํ ์ฟผ๋ฆฌ ์์ฑ๊ธฐ๋ฅผ ์์ฑ ํ ๋ค์ ํ
์ด๋ธ์ ๋ ๋๋งํ๋ ํจ์๋ฅผ ํธ์ถํ๋ ์๋ฒ ์ธก ์ฒ๋ฆฌ๋ฅผ์ํ ๊ฒฝ๋ก๋ฅผ ํธ์ถํ๊ณ ์์ต๋๋ค.
ticket-javascript.blade
<?php
$segments = \Request::segments();
$segment = "";
foreach($segments as $seg){
$segment.="/".$seg;
}
?>
<script type="text/javascript">
function myFunction()
{
return jQuery('#chumper').dataTable({
"sDom": "<'row'<'col-xs-6'l><'col-xs-6'f>r>"+
"t"+
"<'row'<'col-xs-6'i><'col-xs-6'p>>",
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"lengthMenu": [[10, 25, 50, 100, 500], [10, 25, 50, 100, 500]],
"ajax": {
url: "{{url('filter')}}",
data: function (d) {
d.labels = $('select[name=label]').val();
d.tags = $('select[name=tag]').val();
d.segment = "{{$segment}}";
}
},
"aaSorting": sort,
"columnDefs": [
{ "searchable": false, "targets": [6,7] },
{ "visible": last, "targets": 6 },
{"visible": create, "targets":7},
],
"fnCreatedRow": function (nRow, aData, iDataIndex) {
var str = aData[3];
if (str.search("#000") == -1) {
$("td", nRow).css({"background-color": "#F3F3F3", "font-weight": "600", "border-bottom": "solid 0.5px #ddd", "border-right": "solid 0.5px #F3F3F3"});
$("td", nRow).mouseenter(function () {
$("td", nRow).css({"background-color": "#DEDFE0", "font-weight": "600", "border-bottom": "solid 0.5px #ddd", "border-right": "solid 0.5px #DEDFE0"});
});
$("td", nRow).mouseleave(function () {
$("td", nRow).css({"background-color": "#F3F3F3", "font-weight": "600", "border-bottom": "solid 0.5px #ddd", "border-right": "solid 0.5px #F3F3F3"});
});
} else {
$("td", nRow).css({"background-color": "white", "border-bottom": "solid 0.5px #ddd", "border-right": "solid 0.5px white"});
$("td", nRow).mouseenter(function () {
$("td", nRow).css({"background-color": "#DEDFE0", "border-bottom": "solid 0.5px #ddd", "border-right": "solid 0.5px #DEDFE0"});
});
$("td", nRow).mouseleave(function () {
$("td", nRow).css({"background-color": "white", "border-bottom": "solid 0.5px #ddd", "border-right": "solid 0.5px white"});
});
}
}
});
}
</script>
querybuilder ๊ตฌ์ถ ๊ธฐ๋ฅ
public function table(){
// if (Auth::user()->role == 'admin') {
$ticket = new Tickets();
$tickets = $ticket
->leftJoin('ticket_thread', function ($join) {
$join->on('tickets.id', '=', 'ticket_thread.ticket_id')
->whereNotNull('title')
->where('ticket_thread.is_internal', '<>', 1);
})
->leftJoin('ticket_thread as ticket_thread2', 'ticket_thread2.ticket_id', '=', 'tickets.id')
->Join('ticket_source', 'ticket_source.id', '=', 'tickets.source')
->leftJoin('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
->leftJoin('users as u', 'u.id', '=', 'tickets.user_id')
->leftJoin('users as u1', 'u1.id', '=', 'tickets.assigned_to')
->leftJoin('ticket_attachment', 'ticket_attachment.thread_id', '=', 'ticket_thread.id')
->leftJoin('teams', 'teams.id', '=', 'tickets.team_id')
->leftJoin('ticket_collaborator', 'ticket_collaborator.ticket_id', '=', 'tickets.id')
->select(
'tickets.id',
// 'tickets.team_id',
'ticket_thread.title',
'tickets.ticket_number',
'ticket_priority.priority',
'u.user_name as user_name',
'u1.user_name as assign_user_name',
\DB::raw('max(ticket_thread.updated_at) as updated_at'),
\DB::raw('min(ticket_thread.updated_at) as created_at'),
'u.first_name as first_name',
'u.last_name as last_name',
'u1.first_name as assign_first_name',
'u1.last_name as assign_last_name',
'ticket_priority.priority_color',
'teams.name',
DB::raw('COUNT(DISTINCT ticket_thread2.id) as countthread'),
DB::raw('COUNT(ticket_attachment.thread_id) as countattachment'),
DB::raw('COUNT(ticket_collaborator.ticket_id) as countcollaborator'),
'tickets.status',
'tickets.user_id',
'tickets.priority_id', 'tickets.assigned_to',
'ticket_status.name as tickets_status',
'ticket_source.css_class as css',
DB::raw('substring_index(group_concat(ticket_thread.poster order by ticket_thread.id desc) , ",", 1) as last_replier'),
DB::raw('substring_index(group_concat(ticket_thread.title order by ticket_thread.id asc) , ",", 1) as ticket_title'),
'u.active as verified')
->groupby('tickets.id');
return \Ttable::getTable($table); // call to function which renders table
}
๋ง์ง๋ง์ผ๋ก ํ ์ด๋ธ์ ๋ฐ์ดํฐ๋ฅผ ๋ ๋๋งํ๋ ํจ์
public static function getTable($tickets) {
return \Datatables::of($tickets)
->addColumn('id', function ($tickets) {
return "<input type='checkbox' name='select_all[]' id='" . $tickets->id . "' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='" . $tickets->id . "'></input>";
})
->addColumn('title', function ($tickets) {
if (isset($tickets->ticket_title)) {
$string = mb_substr($tickets->ticket_title, 0, 20, 'UTF-8');
} else {
$string = Lang::get('lang.no-subject');
}
$collab = $tickets->countcollaborator;
if ($collab > 0) {
$collabString = ' <i class="fa fa-users"></i>';
} else {
$collabString = null;
}
$attachCount = $tickets->countattachment;
if ($attachCount > 0) {
$attachString = ' <i class="fa fa-paperclip"></i>';
} else {
$attachString = '';
}
$css = $tickets->css;
$titles = '';
if ($tickets->ticket_title) {
$titles = $tickets->ticket_title;
}
$tooltip_script = self::tooltip($tickets->id);
return "<div class='tooltip1' id='tool" . $tickets->id . "'>
<a href='" . route('ticket.thread', [$tickets->id]) . "'>" . ucfirst($string) . " <span style='color:green'>(" . $tickets->countthread . ") <i class='" . $css . "'></i></span>
</a>" . $collabString . $attachString . $tooltip_script .
"<span class='tooltiptext' id='tooltip" . $tickets->id . "'>Loading...</span></div>";
})
->addColumn('ticket_number', function ($tickets) {
return "<a href='" . route('ticket.thread', [$tickets->id]) . "' title='" . $tickets->ticket_number . "'>#" . $tickets->ticket_number . '</a>';
})
->addColumn('priority', function ($tickets) {
$rep = ($tickets->last_replier == 'client') ? '#F39C12' : '#000';
$priority = $tickets->priority;
if ($priority != null) {
$prio = '<button class="btn btn-xs ' . $rep . '" style="background-color: ' . $tickets->priority_color . '; color:#F7FBCB">' . ucfirst($tickets->priority) . '</button>';
} else {
$prio = $tickets->last_relier_role;
}
return $prio;
})
->addColumn('user_name', function ($tickets) {
$from = $tickets->first_name;
$url = route('user.show', $tickets->user_id);
$name = $tickets->user_name;
if ($from) {
$name = utfEncoding($tickets->first_name) . ' ' . utfEncoding($tickets->last_name);
}
$color = '';
if ($tickets->verified == 0 || $tickets->verified == '0') {
$color = "<i class='fa fa-exclamation-triangle' title='" . Lang::get('lang.accoutn-not-verified') . "'></i>";
}
return "<a href='" . $url . "' title='" . Lang::get('lang.see-profile1') . ' ' . ucfirst($name) . ''' . Lang::get('lang.see-profile2') . "'><span style='color:#508983'>" . ucfirst(str_limit($name, 30)) . ' <span style="color:#f75959">' . $color . '</span></span></a>';
})
->addColumn('assign_user_name', function ($tickets) {
if ($tickets->assigned_to == null && $tickets->name == null) {
return "<span style='color:red'>Unassigned</span>";
} else {
$assign = $tickets->assign_user_name;
if ($tickets->assigned_to != null) {
$assign = utfEncoding($tickets->assign_first_name) . ' ' . utfEncoding($tickets->assign_last_name);
$url = route('user.show', $tickets->assigned_to);
return "<a href='" . $url . "' title='" . Lang::get('lang.see-profile1') . ' ' . ucfirst($assign) . ''' . Lang::get('lang.see-profile2') . "'><span style='color:green'>" . mb_substr(ucfirst($assign), 0, 30, 'UTF-8') . '</span></a>';
} else{
$url1 = "#";
return "<a href='" . $url1 . "' title='" . Lang::get('lang.see-profile1') . ' ' . ucfirst($tickets->name) . ''' . Lang::get('lang.see-profile2') . "'><span style='color:green'>" . mb_substr(ucfirst($tickets->name), 0, 30, 'UTF-8') . '</span></a>';
}
}
})
->addColumn('updated_at', function ($tickets) {
$TicketDatarow = $tickets->updated_at;
$updated = '--';
if ($TicketDatarow) {
$updated = $tickets->updated_at;
}
return '<span style="display:none">' . $updated . '</span>' . UTC::usertimezone($updated);
})
->addColumn('created_at', function ($tickets) {
$TicketDatarow = $tickets->created_at;
$updated = '--';
if ($TicketDatarow) {
$updated = $tickets->created_at;
}
return '<span style="display:none">' . $updated . '</span>' . UTC::usertimezone($updated);
})
->make();
}
์ด๊ฒ์ ์ฒ์ 500 ๊ฐ์ ๋ ์ฝ๋์ ๋ํด ๋น ๋ฅด๊ฒ ์๋ํ์ง๋ง ๋ฐ์ดํฐ๊ฐ ์ฆ๊ฐํ๋ฉด ๋๋ ค์ง๋๋ค.
php7, WAMP, mysql 5.7.14๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
@ssuhat ์ด ๊ธด ๋๊ธ์ ์ถ๊ฐํด
์ด๊ฒ์ ๋ํด์๋ ํ์คํ์ง ์์ง๋ง ๋ฐ๋ชจ ์ฑ์์๋ Digital Ocean์ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ์๋ต์ด ์กฐ๊ธ ๋น ๋ฅด๋ค๊ณ ์๊ฐํฉ๋๋ค. ์๋ฒ์์ ๋ค๋ฅธ ์ผ์ด ๋ฐ์ํด์ผํฉ๋๊น? ๋ก๊ทธ์ ์๋ฒ ๋ฆฌ์์ค๋ฅผ ํ์ธ ํ์๊ฒ ์ต๋๊น?
@yajra ์ ๋ Laravel Forge๋ฅผ ์ฌ์ฉํ์ฌ ์๋ฒ๋ฅผ ์ฒ๋ฆฌํ๊ณ ์์ต๋๋ค. ๊ทธ๋์ ์๋ฒ ๋ฌธ์ ๊ฐ ์๋๋ผ๊ณ ์๊ฐํฉ๋๋ค.
@yajra ๋์๊ฒ ์ด๋ค ์ ์์ด ์์ต๋๊น?
์๋ ํ์ธ์, ์ ๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
IM์ 25.000 ๊ฐ์ ๋ ์ฝ๋ ํ ์ด๋ธ์์ 3 ๊ฐ์ ์กฐ์ธ์ผ๋ก 8 ๊ฐ์ ํ๋๋ฅผ ์ ํํ๊ณ ์์ผ๋ฉฐ ์ด๊ฒ์ ๋๋ฆฝ๋๋ค. (ํ์ด์ง ๋น 25 ๊ฐ ๋ ์ฝ๋ ๋น 8 ์ด)
์๋๋ฅผ ๋์ด๊ธฐ์ํ ๋ช ๊ฐ์ง ํ? ๊ฐ์ฌ
๋๋ฆฐ ์ฟผ๋ฆฌ ๋ก๊ทธ๋ฅผ ํ์ฑํํ๊ณ ๊ถ์ฅ ์ฌํญ์ด ์๋์ง ํ์ธํ ์ ์์ต๋๊น?
@ssuhat ๋ฐ @ mariani10 ์ ์ ์ ์ผ๋ฟ์ ๋๋ค (์ด๋ฏธ ์ํ ํ ๊ฒฝ์ฐ ๋ฌด์). ์ฟผ๋ฆฌ ์คํ ์๊ฐ์ ํ์ธํ๊ณ ์ต์ ํํ์ญ์์ค. ์ ๊ฒฝ์ฐ์๋ ์ ๊ฐ ์์ฑํ ์ฟผ๋ฆฌ๊ฐ ๋๋ ค์ ๋ฐ์ดํฐ ํ ์ด๋ธ ๋ก๋ฉ ์๋๊ฐ ๋๋ ค์ก์ต๋๋ค. ์ฟผ๋ฆฌ๋ฅผ ์ต์ ํํ๋ฉด ์ด์ ๋ ๋นจ๋ฆฌ ์๋ํฉ๋๋ค.
์ธ๋ฑ์ค ์ถ๊ฐ๋ ์ฑ๋ฅ ํฅ์์ ํต์ฌ์ด ๋ ์ ์์ต๋๋ค.
๋ฐ๊พธ๋ค:
$brands = Brand::select('id', 'name');
=> $brands = Brand::query();
์, ์ฟผ๋ฆฌ ์ธ๋ฑ์ฑ ๋ฐ ์ต์ ํ๋ ์ฑ๋ฅ ์ ํ๋ฅผ์ํ ์๋ฃจ์ ์ ๋๋ค. ๋ฌผ๋ก ์ปฌ๋ ์ ์ ์ฌ์ฉํ์ง ๋ง์ญ์์ค. ๊ฐ์ฌ!
์ด ํ ๋ก ์ ์ถ๊ฐํ๊ธฐ ์ํด ์ฟผ๋ฆฌ๋ฅผ Datatables์ ์ ๋ฌํ๋์ง ํ์ธํ ํ (์ปฌ๋ ์
์ด ์๋-์์ ์ฃผ์ ์ฐธ์กฐ)-์, ์ธ๋ฑ์ค๋ฅผ ์ถ๊ฐ ํ ์ ์์ง๋ง ์ค์ ๋ก๋ ์ด์ ๋ณตํฉ ์ธ๋ฑ์ค๋ฅผ ๋ง๋ค๊ณ ์ถ์ต๋๋ค. ๋ค์ ์ ํํฉ๋๋ค. ์๋ฅผ ๋ค์ด ์ฟผ๋ฆฌ๊ฐ SELECT foo, bar, MAX(created) WHERE ... GROUP BY foo, bar'
์ ๊ฐ์ ๊ฒฝ์ฐ foo, bar, created_at ์ด์ ๋ณตํฉ ์์ธ ์ ์ํฉ๋๋ค. ์ด ์์
์ ์ํํ์ ๋ ์ฟผ๋ฆฌ ์๋๊ฐ 50 % ๊ฐ์ํ์ต๋๋ค.
๋นจ๋ฆฌ ๊ฐ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋๋ ์์ ์ laravel pagination 1000 ๋ ์ฝ๋๋ฅผ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ datatable์ ์ ์ฉํ๊ณ jquery datatable ํ๋จ ํ์ด์ง ๋งค๊น์ ์ ๊ฑฐํ์ต๋๋ค. ๊ด์ฐฎ์์
๋ฐ๊พธ๋ค:
$brands = Brand::select('id', 'name');
=>$brands = Brand::query();
์ด๊ฒ์ด ์ต์์ ์๋ฃจ์ ์ ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์, ์ฟผ๋ฆฌ ์ธ๋ฑ์ฑ ๋ฐ ์ต์ ํ๋ ์ฑ๋ฅ ์ ํ๋ฅผ์ํ ์๋ฃจ์ ์ ๋๋ค. ๋ฌผ๋ก ์ปฌ๋ ์ ์ ์ฌ์ฉํ์ง ๋ง์ญ์์ค. ๊ฐ์ฌ!