EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jkdoyle on May 23, 2017, 11:07:49 AM



Title: reload combogrid after new record added
Post by: jkdoyle on May 23, 2017, 11:07:49 AM
Hello all

I have a combogrid that I've paired with a "add new record" feature. What I want is fwhen the user creates a new record, the combogrid reloads in order to reflect the newly entered data (correct record desc in the textfield and record selected and scrolled to  in combogrid).  Currently, on submission of the form, I have no problem with reloading the grid or using 'setValue' to set the value and display of the combogrid to the new record. However, due to the number of records, I'm using scrollview with paging set to 10, and I'm having problems figuring out how to get the combogrid to scroll to the newly entered record.  Any help?

Here's an example from the save record function once it has the object result:

Code:
var new_record = result.new_record;
var new_desc = result.new_desc;

var grid = $('#mycombo').combogrid('grid');
grid.datagrid('load');
grid.datagrid('selectRecord',{recordid: new_record});

$('mycombo').combogrid('setValue', {recordid: new_record, desc: new_desc});

Where do I go from here?  I get null or -1 values when I try to use getSelected or getRowIndex. I'm assuming this is because I'm using scrollview?  I am also using a remote datasource in a php file with filtering.

Any help would be appreciated.




Title: Re: reload combogrid after new record added
Post by: jarry on May 24, 2017, 12:13:46 AM
Once you get the datagrid object, you can call 'getRowIndex' method to get the special row's index and call 'scrollTo' method to scroll to it.
Code:
var index = grid.datagrid('getRowIndex',...);
grid.datagrid('scrollTo', {
  index: index,
  callback: function(){
    // do something here
  }
});

If you just want to append a new row to the datagrid, please call 'appendRow' method instead of reloading all the rows. Please make sure to download the 'datagrid-scrollview.js' file from https://www.jeasyui.com/extension/datagridview.php