I used a lazy load technique. In my example I'm using my datepicker grid component, but it's the same principle:
First, define your placeholder:
<div aura:id="datePickerContainer" class="slds-p-horizontal--small slds-m-top--x-small slds-size--1-of-2 slds-medium-size--1-of-3 slds-large-size--2-of-12">
{!v.body}
<!-- initial date display - note, no picker present to improve performance-->
<div aura:id="initialInput" class="slds-form-element">
<label aura:id="initialInputDateElementLabel" class="slds-form-element__label" for="closedate">Reset Date</label>
<div aura:id="initialInputDateElement" class="slds-form-element__control slds-input-has-icon slds-input-has-icon--right slds-float--left">
<ui:inputText class="slds-input" label="" value="MM/dd/yyyy" click="{!c.replaceInputWithPicker}" placeholder="MM/dd/yyyy" />
</div>
</div>
</div>
When the user clicks, you then replace the element:
replaceInputWithPicker: function(component) {
var datePickerContainer = component.find('datePickerContainer');
var initialInput = component.find('initialInput');
var initialInputDateElement = component.find('initialInputDateElement');
var initialInputDateElementLabel = component.find('initialInputDateElementLabel');
var activity = component.get("v.activity");
$A.util.removeClass(datePickerContainer, 'custom-hide');
$A.createComponent(
"c:DatePicker", {
"aura:id": "resetDate",
"label": "Your Date",
"labelClass": "slds-form-element__label",
"placeholder": "New Event Date",
"value": activity.nextEventDate,
"formatSpecifier": "MM/dd/yyyy",
"style": "height: 30px; display: inline-block;",
"dateChangeEvent": component.getReference("c.handleDateChange")
},
function(datePicker, status, errorMessage) {
//Add the new button to the body array
if (status === "SUCCESS") {
//define custom-hide in your css - display:none;
$A.util.addClass(initialInput, ' custom-hide ');
datePickerContainer.set("v.body", []);
var body = datePickerContainer.get("v.body");
body.push(datePicker);
datePickerContainer.set("v.body", body);
datePicker.showCalendar();
} else if (status === "INCOMPLETE") {
console.log("No response from server or client is offline.")
} else if (status === "ERROR") {
console.log("Error: " + errorMessage);
}
}
);
}
This makes a HUGE difference to speed.
Just replace my custom date picker component with your UI:InputDate.
Or use mine. It's here: datepicker
Also, note the date change event method dynamic reference in the replaceInputWithPicker function - it's very useful to be able to reference existing functions and add them dynamically to your dynamic components!
Also, I don't think you need the {!body}
item - I left it in there because I've forgotten if it's needed or not!!