optikalefx / OpenJS-Grid

OpenJS Grid is the easiest jQuery Grid ever. With very little work you can have a data grid that can do everything from sorting and searching to complex database queries. Best of all, its open source. So you can learn how it's all done.
http://square-bracket.com/openjs
MIT License
96 stars 46 forks source link

Add Button #34

Closed trcharlie closed 11 years ago

trcharlie commented 11 years ago

I need an Add-Button in my Grids but I'm stuck when it comes to reloading the grid with the added Row. What i have done so far is:

in grid.js on line 664 I added:

<a class='gridAdd btn btn-primary' href='#'>+</a>\

in line 270 I added:

$grid._on("click",".gridAdd", self.addRow, self);

line 2004:

        addRow : function() {
            var self = this;

            $.post(self.opts.action, {add:true}, function(success) {
                    if(success) {
                    console.log('Row added');

                    } else {
                        self.error("Failed to Add");
                        console.log('Row not added');
                    }
                    this.grid("load");                  
                });

in grid.php the function add() is not a comment anymore. So if I click on the Add-Button, a new dataset is created in the database. BUT i need the grid to be refreshed. I tried this.grid("load"); and some other variants but none of them refreshed the grid. I'm sure there's just a line of code I'm missing so please help me.

regards, charlie

optikalefx commented 11 years ago

So you shouldn't modify grid.js

1) You can add a button in the loadComplete event using jQuery. 2) Then bind an click event to that and do your ajax work. 3) Then call .load() as normal to reload it after the ajax call

trcharlie commented 11 years ago

I see, thanks a lot