Title: An easy way to sort groups in datagrid groupview [SOLVED] Post by: Juan Antonio Martínez on April 29, 2015, 01:21:48 PM I'm looking for a solution to show datagrid groups sorted in an specific order provided by evaluating some fields from group members
My groupFormater() function comes here: Code: // value: Team name ¿Any suggestion?. Looking at groupview code, I figure some kind of sorting once the datagrid elements have been parsed and group list composed, but unsure about right way to do in a generic way Thanks in advance. Juan Antonio Title: Re: An easy way to sort groups in datagrid groupview ? Post by: stworthy on April 29, 2015, 07:43:05 PM A possible way to solve this issue is to extend the group view and define your own sorting rules. The code below shows how to achieve this:
Code: var gview = $.extend({}, groupview, { Title: Re: An easy way to sort groups in datagrid groupview ? Post by: Juan Antonio Martínez on April 30, 2015, 05:16:14 PM Thanks!
With a minor changes it works for me Code: /** A last two questions: - "rownumbers" options affect data rows, not group rows. Any way to change this behaviour? - Today Upgraded to easyui-1.4.2... and my group formatter method doesn't run anymore :-( I'd like groupFormatter to generate a table-like text info, but seems that datagrid css styles overrides mine when group rows are expanded. ¿Any way to solve this? Thanks in advance Juan Antonio Title: Re: An easy way to sort groups in datagrid groupview ? Post by: stworthy on April 30, 2015, 05:58:45 PM What happen with your 'groupFormatter' function? Please describe your issue in more detail.
Title: Re: An easy way to sort groups in datagrid groupview ? Post by: Juan Antonio Martínez on May 01, 2015, 01:03:55 AM sure:
groupFormatter relevant code: Code: // this works, but I want to tabulate output Code: .team-results {display:inline-block;table-layout:fixed; width:725px;}/*Setting the table width is important!*/ When at least one group row is collapsed, every thing works as expected. Here comes my capture showing DOM inspector: (https://dl.dropboxusercontent.com/u/72813204/groupview1.png) But when all group rows are expanded, text dissappears... but DOM Inspector says it is still there: (https://dl.dropboxusercontent.com/u/72813204/groupview2.png) I suspect any issue on groupview renderer code , but unsure.. Juan Antonio Title: Re: An easy way to sort groups in datagrid groupview [SOLVED] Post by: Juan Antonio Martínez on May 01, 2015, 03:36:45 AM Finally I found the problem: groupFormatter's table width and datagrid scrollbar
When scrollbar appears, the group header width becomes greater than available space... and inline-block's display attributes, makes it to be rendered at next line... and thus not shown. Just setting up the right width value, gets allways displayed as expected I'll investigate how to automagically expand table width to fit available space, but not now :-) Thanks. Juan Antonio Title: Re: An easy way to sort groups in datagrid groupview [SOLVED] Post by: vencelylalas on May 05, 2015, 06:19:10 PM var gview = $.extend({}, groupview, {
onBeforeRender: function(target, rows){ groupview.onBeforeRender.call(this, target, rows); var state = $.data(target, 'datagrid'); var opts = state.options; if (opts.sortName != opts.groupField){ return; } var groups = this.groups; groups.sort(function(a,b){ var v1 = sumValue(a.rows, 'listprice'); var v2 = sumValue(b.rows, 'listprice'); return (opts.sortOrder=='asc'?1:-1)*(v1>v2?1:-1); }); var index = 0; var newRows = []; for(var i=0; i<groups.length; i++){ var group = groups; group.startIndex = index; index += group.rows.length; newRows = newRows.concat(group.rows); } state.data.rows = newRows; function sumValue(rows,field){ var v = 0; $.map(rows, function(row){ v += row[field]; }); return v; } } }) $(function(){ $('#dg').datagrid({ view: gview, //... }) }) |