Unfortunately you cannot get a fixed amount of items in a microflow, so I would retrieve the objects in a Java action instead, there you can do an xpath query limited by amount. You can just pass this list to the generate document action in your microflow.
If the datagrid is nested, use a microflow as data source and call the Java action there.