This is a migrated thread and some comments may be shown as answers.

is there a way to improve the kendo grid data?

3 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Austin
Top achievements
Rank 1
Austin asked on 19 Sep 2016, 02:58 AM

I have create a simple kendo grid with sample data where i would like to optimize the grid. is there a way to remove or hide the "Quantity" field whenever the my sample data doesn't contain quantity?

 

sample code

 

 

3 Answers, 1 is accepted

Sort by
0
Eduardo Serra
Telerik team
answered on 19 Sep 2016, 06:10 PM
Hello Austin,

We use the hideColumn method whenever we want to hide a column in the grid. To see if the column is empty, we get the data for that column and check it.

I prepared a sample in the Kendo UI Dojo, using what you provided as a base, that shows the basic logic of this approach; you can take a look at it here.

I hope this helps!

Regards,
Eduardo Serra
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Austin
Top achievements
Rank 1
answered on 20 Sep 2016, 02:12 AM

Thank for the solution you had provided. It work perfectly. If i want to check for each data then its gonna have a lot of the if statement ?

is this is best way to do i

var disZeroes = true;
var quanZeroes = true;
 
for (var i = 0; i < data.length; i++) {
   if (data[i].Discount!= null) {
      disZeroes = false;
      break;
    }
   if (data[i].quantity!= null) {
      quanZeroes = false;
      break;
    }
}
 
 if (disZeroes) {
grid.hideColumn("quantity")
 }
 if (quanZeroes) {
 grid.hideColumn("quantity")
}

0
Accepted
Daniel
Telerik team
answered on 22 Sep 2016, 06:50 AM
Hello Austin,

You could simplify the code by taking advantage of the javascript array:
var hiddenColumns = [];
 
for (var i = 0; i < data.length; i++) {
    for (var prop in data[i]) {
        hiddenColumns.push(prop);
    }
}

You can then traverse the array and hide these columns as per your requirements.

Regards,
Daniel
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Grid
Asked by
Austin
Top achievements
Rank 1
Answers by
Eduardo Serra
Telerik team
Austin
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or