Skip to main content
Version: 4.9.0

MasonryInfiniteGrid

class MasonryInfiniteGrid

MasonryInfiniteGrid is a grid that stacks items with the same width as a stack of bricks. Adjust the width of all images to the same size, find the lowest height column, and insert a new item.

constructor

new MasonryInfiniteGrid(container, options)
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
containerHTMLElement | string

A base element for a module

optionsMasonryInfiniteGridOptions

The option object of the MasonryInfiniteGrid module

Methods

renderItems

inherited

Rearrange items to fit the grid and render them. When rearrange is complete, the renderComplete event is fired.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
optionsRenderOptions✔️{}

Options for rendering.

import { MasonryInfiniteGrid } from "@egjs/infinitegrid";
const grid = new MasonryInfiniteGrid();

grid.on("renderComplete", e => {
console.log(e);
});
grid.renderItems();

getWrapperElement

inherited

Returns the wrapper element specified by the user.

getScrollContainerElement

inherited

Returns the container element corresponding to the scroll area.

getContainerElement

inherited

Returns the container element containing item elements.

syncItems

inherited

When items change, it synchronizes and renders items.

Returns: this

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
itemsInfiniteGridItemInfo[]

Options for rendering.

setCursors

inherited

Change the currently visible groups.

Returns: this

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
startCursornumber

first index of visible groups.

endCursornumber

last index of visible groups.

useFirstRenderboolean✔️

Whether the first rendering has already been done.

getStartCursor

inherited

Returns the first index of visible groups.

Returns: number

getEndCursor

inherited

Returns the last index of visible groups.

Returns: number

append

inherited

Add items at the bottom(right) of the grid.

Returns: this


    • An instance of a module itself

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
itemsInfiniteGridInsertedItems

items to be added

groupKeystring | number✔️

The group key to be configured in items. It is automatically generated by default.

ig.append(`<div class="item">test1</div><div class="item">test2</div>`);
ig.append([`<div class="item">test1</div>`, `<div class="item">test2</div>`]);
ig.append([HTMLElement1, HTMLElement2]);

prepend

inherited

Add items at the top(left) of the grid.

Returns: this


    • An instance of a module itself

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
itemsInfiniteGridInsertedItems

items to be added

groupKeystring | number✔️

The group key to be configured in items. It is automatically generated by default.

ig.prepend(`<div class="item">test1</div><div class="item">test2</div>`);
ig.prepend([`<div class="item">test1</div>`, `<div class="item">test2</div>`]);
ig.prepend([HTMLElement1, HTMLElement2]);

insert

inherited

Add items to a specific index.

Returns: this


    • An instance of a module itself

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
indexnumber

index to add

itemsInfiniteGridInsertedItems

items to be added

groupKeystring | number✔️

The group key to be configured in items. It is automatically generated by default.

ig.insert(2, `<div class="item">test1</div><div class="item">test2</div>`);
ig.insert(3, [`<div class="item">test1</div>`, `<div class="item">test2</div>`]);
ig.insert(4, [HTMLElement1, HTMLElement2]);

insertByGroupIndex

inherited

Add items based on group index.

Returns: this


    • An instance of a module itself

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
groupIndexnumber

group index to add

itemsInfiniteGridInsertedItems

items to be added

groupKeystring | number✔️

The group key to be configured in items. It is automatically generated by default.

ig.insertByGroupIndex(2, `<div class="item">test1</div><div class="item">test2</div>`);
ig.insertByGroupIndex(3, [`<div class="item">test1</div>`, `<div class="item">test2</div>`]);
ig.insertByGroupIndex(4, [HTMLElement1, HTMLElement2]);

getStatus

inherited

Returns the current state of a module such as location information. You can use the setStatus() method to restore the information returned through a call to this method.

Returns: InfiniteGridStatus

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
typeSTATUS_TYPE✔️

STATUS_TYPE.NOT_REMOVE = Get all information about items. STATUS_TYPE.REMOVE_INVISIBLE_ITEMS = Get information on visible items only. STATUS_TYPE.MINIMIZE_INVISIBLE_ITEMS = Compress invisible items. You can replace it with a placeholder. STATUS_TYPE.MINIMIZE_INVISIBLE_GROUPS = Compress invisible groups.

includePlaceholdersboolean✔️

Whether to include items corresponding to placeholders.

setPlaceholder

inherited

You can set placeholders to restore status or wait for items to be added.

Returns: this

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
infoPartial<InfiniteGridItemStatus> | null

The placeholder status.

setLoading

inherited

You can set placeholders to restore status or wait for items to be added.

Returns: this

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
infoPartial<InfiniteGridItemStatus> | null

The placeholder status.

appendPlaceholders

inherited

Add the placeholder at the end.

Returns: InsertedPlaceholdersResult

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
itemsnumber | InfiniteGridItemStatus[]

Items that correspond to placeholders. If it is a number, it duplicates the number of copies.

groupKeystring | number✔️

The group key to be configured in items. It is automatically generated by default.

prependPlaceholders

inherited

Add the placeholder at the start.

Returns: InsertedPlaceholdersResult

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
itemsnumber | InfiniteGridItemStatus[]

Items that correspond to placeholders. If it is a number, it duplicates the number of copies.

groupKeystring | number✔️

The group key to be configured in items. It is automatically generated by default.

removePlaceholders

inherited

Remove placeholders

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
type"start" | "end" | {groupKey: string | number}

Remove the placeholders corresponding to the groupkey. When "start" or "end", remove all placeholders in that direction.

setStatus

inherited

Sets the status of the InfiniteGrid module with the information returned through a call to the getStatus() method.

Returns: this

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
statusInfiniteGridStatus

status object of the InfiniteGrid module.

useFirstRenderboolean✔️

Whether the first rendering has already been done.

removeGroupByIndex

inherited

Removes the group corresponding to index.

Returns: this

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
indexnumber

removeGroupByKey

inherited

Removes the group corresponding to key.

Returns: this

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
keynumber | string

removeByIndex

inherited

Removes the item corresponding to index.

Returns: this

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
indexnumber

removeByKey

inherited

Removes the item corresponding to key.

Returns: this

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
keystring | number

updateItems

inherited

Update the size of the items and render them.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
itemsInfiniteGridItem[]✔️

Items to be updated.

optionsRenderOptions✔️{}

Options for rendering.

getItems

inherited

Return all items of InfiniteGrid.

Returns: InfiniteGridItem[]

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
includePlaceholdersboolean✔️

Whether to include items corresponding to placeholders.

getVisibleItems

inherited

Return visible items of InfiniteGrid.

Returns: InfiniteGridItem[]

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
includePlaceholdersboolean✔️

Whether to include items corresponding to placeholders.

getRenderingItems

inherited

Return rendering items of InfiniteGrid.

Returns: InfiniteGridItem[]

getGroups

inherited

Return all groups of InfiniteGrid.

Returns: InfiniteGridGroup[]

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
includePlaceholdersboolean✔️

Whether to include groups corresponding to placeholders.

getVisibleGroups

inherited

Return visible groups of InfiniteGrid.

Returns: InfiniteGridGroup[]

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
includePlaceholdersboolean✔️

Whether to include groups corresponding to placeholders.

wait

inherited

Set to wait to request data.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
direction"start" | "end"✔️DIRECTION.END

direction in which data will be added.

ready

inherited

When the data request is complete, it is set to ready state.

isWait

inherited

Returns whether it is set to wait to request data.

destroy

inherited

Releases the instnace and events and returns the CSS of the container and elements.

Returns: void

trigger

inherited

Trigger a custom event.

Returns: this

  • An instance of the component itself

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventstring | ComponentEvent

The name of the custom event to be triggered or an instance of the ComponentEvent

paramsArray<any> | $ts:...

Event data to be sent when triggering a custom event

import Component, { ComponentEvent } from "@egjs/component";

class Some extends Component<{
beforeHi: ComponentEvent<{ foo: number; bar: string }>;
hi: { foo: { a: number; b: boolean } };
someEvent: (foo: number, bar: string) => void;
someOtherEvent: void; // When there's no event argument
}> {
some(){
if(this.trigger("beforeHi")){ // When event call to stop return false.
this.trigger("hi");// fire hi event.
}
}
}

const some = new Some();
some.on("beforeHi", e => {
if(condition){
e.stop(); // When event call to stop, `hi` event not call.
}
// `currentTarget` is component instance.
console.log(some === e.currentTarget); // true

typeof e.foo; // number
typeof e.bar; // string
});
some.on("hi", e => {
typeof e.foo.b; // boolean
});
// If you want to more know event design. You can see article.
// https://github.com/naver/egjs-component/wiki/How-to-make-Component-event-design%3F

once

inherited

Executed event just one time.

Returns: this

  • An instance of the component itself

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventNamestring | $ts:...

The name of the event to be attached or an event name - event handler mapped object.

handlerToAttachfunction | $ts:...✔️

The handler function of the event to be attached

import Component, { ComponentEvent } from "@egjs/component";

class Some extends Component<{
hi: ComponentEvent;
}> {
hi() {
alert("hi");
}
thing() {
this.once("hi", this.hi);
}
}

var some = new Some();
some.thing();
some.trigger(new ComponentEvent("hi"));
// fire alert("hi");
some.trigger(new ComponentEvent("hi"));
// Nothing happens

hasOn

inherited

Checks whether an event has been attached to a component.

Returns: boolean

  • Indicates whether the event is attached.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventNamestring

The name of the event to be attached

import Component from "@egjs/component";

class Some extends Component<{
hi: void;
}> {
some() {
this.hasOn("hi");// check hi event.
}
}

on

inherited

Attaches an event to a component.

Returns: this

  • An instance of a component itself

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventNamestring | $ts:...

The name of the event to be attached or an event name - event handler mapped object.

handlerToAttachfunction | $ts:...✔️

The handler function of the event to be attached

import Component, { ComponentEvent } from "@egjs/component";

class Some extends Component<{
hi: void;
}> {
hi() {
console.log("hi");
}
some() {
this.on("hi",this.hi); //attach event
}
}

off

inherited

Detaches an event from the component.
If the eventName is not given this will detach all event handlers attached.
If the handlerToDetach is not given, this will detach all event handlers for eventName.

Returns: this

  • An instance of a component itself

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eventNamestring | $ts:...✔️

The name of the event to be detached

handlerToDetachfunction | $ts:...✔️

The handler function of the event to be detached

import Component, { ComponentEvent } from "@egjs/component";

class Some extends Component<{
hi: void;
}> {
hi() {
console.log("hi");
}
some() {
this.off("hi",this.hi); //detach event
}
}

Events

changeScroll

inherited

This event is fired when scrolling.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eInfiniteGrid.OnChangeScroll

The object of data to be sent to an event

requestAppend

inherited

The event is fired when scrolling reaches the end or when data for a virtual group is required.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eInfiniteGrid.OnRequestAppend

The object of data to be sent to an event

requestPrepend

inherited

The event is fired when scrolling reaches the start or when data for a virtual group is required.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eInfiniteGrid.OnRequestPrepend

The object of data to be sent to an event

contentError

inherited

The event is fired when scrolling reaches the start or when data for a virtual group is required.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eInfiniteGrid.OnContentError

The object of data to be sent to an event

renderComplete

inherited

This event is fired when the InfiniteGrid has completed rendering.

PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
eInfiniteGrid.OnRenderComplete

The object of data to be sent to an event