hi, my datatable expand is slow how to improve that?
hi, my datatable expand is slow how to improve that?
farhan07
Posts: 7Questions: 1Answers: 0
$(".expand-all").click(function(e) {
e.stopImmediatePropagation();
var name;
collapsedGroups = [];
$(".dataTables_processing").show("fast", function() {
var _dataSrc = tableNew.rowGroup().dataSrc();
var tableArray = [];
var dataSrcArray = Object.keys(_dataSrc);
var aggregationIndex = 0;
_dataSrc.forEach(function(_dataSrcIndex) {
tableArray.push(tableNew.column(_dataSrcIndex).data())
})
//WE DON'T NEED TO EXCECUTE THE CHILDS, SO WE USE THE BELOW VARIABLE TO AVOID THE TIME CONSUME
for(j=0; j<tableArray.length; j++){
aggregationIndex = aggregationIndex +1;
//WE NEED TO ITERATE ONLY THE PARENT AND THE LAST CHILD
if(aggregationIndex == 1){
tableArray[j].unique().each( function ( name, index ) {
//WHEN THERE IS MULTIPLE AGGREGATION WE HAVE TO SHOW THE PARENT ROW
if(j>0){
for(k=0; k< tableArray[0].unique().length;k++){
var parent = tableArray[0][k];
collapsedGroups[parent+name] = false;
}
}else{
collapsedGroups[name] = false;
}
} );
}
}
nonNumericColumns(true,table_id,tableNew,groupColumn);
//$('#collapse-all').attr('id','collapse-partial');
$('.collapse-all').addClass('collapse-partial');
$('.collapse-all').removeClass('collapse-partial');
tableNew.draw(false);
console.log("Enter3");
/*tableNew.draw(false); */
$(".dataTables_processing").hide();
});
});
function nonNumericColumns(visibility,table_id,table,groupColumn){
var flagTable;
//var columns = $('#'+table_id).dataTable().dataTableSettings[0].aoColumns;
var columns = table.settings()[0].aoColumns;
var className = "";
var column = "";
$.each(columns, function(i,v) {
className = v.nTh.className;
column = v.idx;
if(!visibility){
if ((className.indexOf("numeric") < 0) && (v.sTitle != '')) {
table.columns( column ).visible( false );
}
}else{
column = v.idx;
table.columns( column ).visible( true );
}
});
//AGGREGATE COLUMNS NOT NEEDED TO SHOW
if(visibility){
table.columns( groupColumn ).visible( false );
}
//CALL PREHIDDEN WHEN WE EXPAND VIEWS - VISIBILITY TRUE MEANS EXPANDING VIEW
if(visibility){
preHidden(table,table_id,true);
}
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
This section of the FAQ should help, it discusses various techniques to improve performance,
Colin
If it doesn't help to resolve the issue, please link to a test case showing the issue.
Allan
sorry allan i not sure to create test case . but i am sure below code to execute number of table rows time so pls optimized that one.
rowGroup: {
startRender: function ( rows, group, level) {
var all;
if (level === 0) {
top = group;
all = group;
} else {
// if parent collapsed, nothing to do
if (!!collapsedGroups[top]) {
return;
}
//THIS IS TO AVOID THE GROUP EMPTY VALUE WHILE COLLAPSE
if(group==''){
all = top + '-';
}else{
all = top + group;
}
}
var collapsed = !!collapsedGroups[all];
//var collapsed = true;
If you can't link to your page showing the issue, you can find how to use external services to host it for you here.
Allan
I am asking simply how to sum rowgroup of all pages of datatable?
Apologies, that wasn't clear to me. The
rows
parameter contains a reference to the rows in the group, so you can sum the data from there. There is an example of how to do that here.Allan
If performance is the issue, I would need a link to a page showing the issue so I can profile it.
Thank you allan aggregation working faster .but collapse group and expand group is slow its take 15 to 18 sec. i found one issue click collapse group table header is collapsed faster but unwanted row hide later
function nonNumericColumns(visibility, table_id, table, groupColumn) {
var columns = table.settings()[0].aoColumns;
function preHidden(table,table_id,draw) {
//var columns = $('#'+table_id).dataTable().dataTableSettings[0].aoColumns;
var columns = table.settings()[0].aoColumns ;
$(".collapse-all").click(function(e) {
e.stopImmediatePropagation();
//console.log('collapse-all');
//PARAMETER TO CONTROL THE SORTING WHEN EXPAND
fullyCollapsed = 1;
nonNumericColumns(false,table_id,tableNew,groupColumn);
var name;
collapsedGroups = [];
var tableArray = [];
var _dataSrc = tableNew.rowGroup().dataSrc();
var dataSrcArray = Object.keys(_dataSrc);
var aggregationIndex = 0;
above code for collapse pls give me the solution
Please give me a test case.
You can use JSFiddle, Stackblitz of something else to host a page if you can't link to your own. I cannot debug the code above in my head.
Allan
Hi, Allan. I have the same issue here everything works fine, except when users try to expend a row the first time it works, then collapse it or expend another row stacks and in the console log we get an error like this
It's working OK in this example, so it must be something with your setup.
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Colin
@koodh - My guess is you are using an old version of DataTables - maybe 2.0.x something? Try updating to the latest 2.1.8 as I reply to this.
Allan