Monday, 12 December 2016

Enabling Upload from Excel for the Grid

Hi All,

Today I want to share with you a way how to enable upload form excel for custom grid.

Actually this is quite simple -

  1. Step 1 - define PXImportAttribute on data the data view under the grid.

  2. public class CSCalendarMaint : PXGraph<CSCalendarMaint, CSCalendar>
    {
    ...
           [PXImport]
           public PXSelect<CSCalendarExceptions> CSCalendarExceptions;
    ...
    }

  3. Step 2 - enable appropriate Grid Mode (Allow Upload) on the grid properties.
This will enable upload button on the grid action bar with standard functionality.

In some cases, you may want to have more control on the import process. In this case you also may implement optional interface: IPXPrepareItems. This interface should be implemented on processing graph itself.

public interface IPXPrepareItems
{
       bool PrepareImportRow(string viewName, IDictionary keys, IDictionary values);
       void PrepareItems(string viewName, IEnumerable items);
       bool RowImported(string viewName, object row, object oldRow);
       bool RowImporting(string viewName, object row);
}
  • PrepareImportRow - This event will be triggered right before insert record to cache. You can review keys and values that will be assigned to new record.
  • PrepareItems - Used to review items before import, but right now does not execute for performance optimizations.
  • RowImporting - This and next events will be executed only if you decided bypass update of existing records. On that event you can decide what to do with existing record if it was in the database before, for example delete it.
  • RowImported -  Here you can control update operation after insert.
Unfortunately right now there is an issues with declaring PXImport attribute on extension, but this thing will be fixed soon and you will have a easy way to import everything instead of typing.

Have a nice development!

No comments: