is there a way to improve the kendo grid data?

4 posts, 1 answers
  1. Austin
    Austin avatar
    8 posts
    Member since:
    Sep 2016

    Posted 18 Sep 2016 Link to this post

    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

     

     

  2. Eduardo Serra
    Admin
    Eduardo Serra avatar
    67 posts

    Posted 19 Sep 2016 Link to this post

    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.
     
  3. Austin
    Austin avatar
    8 posts
    Member since:
    Sep 2016

    Posted 19 Sep 2016 in reply to Eduardo Serra Link to this post

    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")
    }

  4. Answer
    Daniel
    Admin
    Daniel avatar
    4950 posts

    Posted 22 Sep 2016 Link to this post

    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.
     
Back to Top