EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jega on February 14, 2017, 03:19:03 AM



Title: Datagrid delete record and reload problem
Post by: jega on February 14, 2017, 03:19:03 AM
Hi.

I have a datagrid with some records. When i delete a record, and reload it, the record is still in the grid, but deleted from db. close the page and open it Again, the record is not in grid, as espected.

I have to set the browser settings to "Always get the site" (default in browser is Automatic), to remove the record from the grid, on reload, after delete.

What can i do ???



Title: Re: Datagrid delete record and reload problem
Post by: stworthy on February 14, 2017, 07:47:27 AM
After removing the record from the database, please call 'reload' or 'load' method to refresh the datagrid rows. Please look at this example http://www.jeasyui.com/demo/main/index.php?plugin=Application&theme=default&dir=ltr&pitem=Basic%20CRUD


Title: Re: Datagrid delete record and reload problem
Post by: jega on February 14, 2017, 01:14:03 PM
Yes i know how to do it. Here my code.

The treegrid is presenting files in a folder.

Mark a row, push delete. asp code deleting the file, and if ok, reload the treegrid

   function deleteFile(){
       var row = $('#fileBrowser').treegrid('getSelected');
       if (row){
           $.messager.confirm('Verify','Er du sikker på du vil slette '+row.name+' ?',function(r){
               if (r){
                   $.post('data_files.asp?st=deletefile',{fn:row.path},function(data,status,xhr){
                      if (data == 'ok'){
                         $('#fileBrowser').treegrid('reload');
                      }
                   });
               }
           });
       }
   }

BUT, the row remains in treegrid. When reload site, the treegrid shows the remaining rows, as espected.
If the browser settings is "Automatic" load site, it takes the site from cache, and the treegrid reload doesn't Work, but if i change the browser settings to "Always load site", the reload treegrid Works fine.




Title: Re: Datagrid delete record and reload problem
Post by: stworthy on February 14, 2017, 08:46:52 PM
To remove a treegrid row, please call 'remove' method instead.
Code:
$('#fileBrowser').treegrid('remove',row.id);


Title: Re: Datagrid delete record and reload problem
Post by: jega on February 15, 2017, 01:15:00 AM
I can see that method, but the same happens on the datagrid. All my users have to change browser settings.

Add or delete a row to the mysql and reload datagrid, only Works when the browser is setup to load page "On every visit"


Title: Re: Datagrid delete record and reload problem
Post by: jega on February 15, 2017, 01:19:38 AM
It's a cache problem.

Tried to add a row. Row just fine in mysql, but no row showed on reload datagrid.

Closing browser, and open Again, still no row. Change settings in browser to get page every time, and the row is now showed.


Title: Re: [SOLVED] Datagrid delete record and reload problem
Post by: jega on May 09, 2017, 11:16:04 PM
Weeee.

Solved the problem

Had this code

<table id="dgAddressList" class="easyui-datagrid" title="PersonListe" style="width:auto;height:auto" data-options="
            url:'getfromdb.asp?st=personlist&ct=true',
            rownumbers:false,
            checkOnSelect:true,
            method:'get',
            pagination:true,
            singleSelect:false,
            idField:'cpr',
            toolbar:'#toolbarAddressList'">


With this code, adding/removing a line to database and using $('#dgAddressList').datagrid('reload'); will not show the added record before update whole site, OR if the debugger was on, it worked fine.

Removing "method:'get'" or setting it to post, solved the problem