0

I have a button on my page when it's clicked I want to check if my grid has rows

 function CheckBusinessLicense() {
            var data = $('#License').data('tGrid');            
            var tr = JSON.stringify(data);
            alert(tr);
        }

but these return a string of information. How can I find if my grid have data or rows?

user1836442
  • 55
  • 1
  • 9

1 Answers1

0

I had the same issue a few days ago. This is what I came up with.

var grid = $("#License").data("tGrid");
if (grid.data.length != 0)
    alert(grid.data.length);

Enjoy.

IyaTaisho
  • 863
  • 19
  • 42
  • Is giving a error" Unable to get value of the property 'length' – user1836442 Nov 29 '12 at 20:00
  • Strange... When are you trying to check the number of rows? It may have to do something with that. When I did it, I ended up checking it during the OnDataBound event for the grid. – IyaTaisho Nov 29 '12 at 20:09
  • I'm checking after the grid is bound. My function belongs to a save button..trying to check if grid has data before save – user1836442 Nov 29 '12 at 20:24
  • Weirdness. I moved my piece into the save of a button and I was able to get back the proper result. Can you maybe post more so I can see what is up with it? Edit: Maybe do this: alert(grid.data); This should give you [Object object], ... etc. Just checking to see if it recognizes the grid or not. Thanks. – IyaTaisho Nov 29 '12 at 20:46
  • 1
    var grid = $('#License').data('tGrid'); rows = $(grid.element).find(".t-no-data"); alert(rows.length); – user1836442 Nov 29 '12 at 21:00
  • That works too. Weird it couldn't be found using what I had. Glad you found it at the very least. – IyaTaisho Nov 30 '12 at 13:08