dtaalbers-com / au-datatable

Aurelia Datatable, A highly customizable html datatable, build for the Aurelia Framework.

Home Page:https://dtaalbers.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redundant code in samples

MrBliz opened this issue · comments

Not really an issue as such, more of an observation that might be worth pointing out in the demo sample for Aurelia newbies like myself. :)

All of the following code (albeit with the logging messages not customised)

public nextPage = async (parameters: AuDatatableParameters): Promise<AuDatatableResponse> => {
    try {
        let response = await this.fetchData(parameters) as AuDatatableResponse;
        return response;
    } catch (e) {
        alert(`[demo:next_page] Failed to load the data: `);
    }
}


public previousPage = async (parameters: AuDatatableParameters): Promise<AuDatatableResponse> => {
    try {
        let response = await this.fetchData(parameters) as AuDatatableResponse;
        return response;
    } catch (e) {
        alert(`[demo:previous_page] Failed to load the data: `);
    }
}

public changePage = async (parameters: AuDatatableParameters): Promise<AuDatatableResponse> => {
    try {
        let response = await this.fetchData(parameters) as AuDatatableResponse;
        return response;
    } catch (e) {
        alert(`[demo:change_page] Failed to load the data: `);
    }
}

public sort = async (parameters: AuDatatableParameters): Promise<AuDatatableResponse> => {
    try {
        let response = await this.fetchData(parameters) as AuDatatableResponse;
        return response;
    } catch (e) {
        alert(`[demo:sort] Failed to load the data: `);
    }
}

public search = async (parameters: AuDatatableParameters): Promise<AuDatatableResponse> => {
    try {
        let response = await this.fetchData(parameters) as AuDatatableResponse;
        return response;
    } catch (e) {
        alert(`[demo:change_page] Failed to load the data: `);
    }
}

public pageSizeChanged = async (parameters: AuDatatableParameters): Promise<AuDatatableResponse> => {
    try {
        let response = await this.fetchData(parameters) as AuDatatableResponse;
        return response;
    } catch (e) {
        alert(`[demo:change_page] Failed to load the data: `);
    }
}

public filter = async (parameters: AuDatatableParameters): Promise<AuDatatableResponse> => {
    try {
        let response = await this.fetchData(parameters) as AuDatatableResponse;
        return response;
    } catch (e) {
        alert(`[demo:filter] Failed to load the data: `);
    }
}

could be just replaced with this.

public refresh= async (parameters: AuDatatableParameters): Promise<AuDatatableResponse> => {
    try {
        let response = await this.fetchData(parameters) as AuDatatableResponse;
        return response;
    } catch (e) {
        alert( Failed to load the data: `);
    }
}

you could even just bind to the parameters object on the view model

public refresh= async (): Promise<AuDatatableResponse> => {
    try {
        let response = await this.fetchData(parameters) as AuDatatableResponse;
        return response;
    } catch (e) {
        alert( Failed to load the data: `);
    }
}

Like i said, not an issue, just an observation, and I thought i'd post it for the benefit of others that come across the library, that may initially think that the plugin requires a lot of code on the client. :)

Great work by the way. Have the Aurelia team pushed this?

Hi Liam,

I agree that the most function on the viewmodel are redundant. I might clean it up like you suggested and just keep the necessary code needed to be able to run the plugin. It'll stop scaring people away. 😆

Did you get the plugin to work like you wanted it? If so, what are your thoughts about the plugin? Easy enough to use once you get the hang of it? Haven't gotten much feedback yet.

Have the Aurelia team pushed this?

What do you mean by this? 😄

Have the Aurelia team pushed this?

I just mean have you tweeted about it to AureliaEffect and have they spread the word? They have a weekly newsletter, (but seems to be on hiatus now)

I really like it, my only request would be to add debounce as an option for search. I see you removed it in this commit, but adding a debounce as an option would be very useful.

If you want this, i'm happy to submit a pull request this weekend (will be my first OSS contribution! :))

Actually i tell a lie, there's something else. The way that sorting is bound to columns seems a bit wierd.

at the moment before passing the data off to my API i'm having to do this

let sortColumn = "";

        switch (this.parameters.sortColumn.toString()) {
            case "0":
                sortColumn = "id";
                break;
            case "1":
                sortColumn = "customerType";
                break;
            case "2":
                sortColumn = "name"
                break;
            case "3":
                sortColumn = "email"
                break;
            case "4":
                sortColumn = "number"
                break;
            case "5":
                sortColumn = "createdDate"
                break;
        }

Which doesn't seem right.

I would either replace or complement the current sort function with binding to a list of column names in the same order as the columns eg [id,name;type] instead of [0,1,2] or add a sortField attribute to the element that is sortable?

Hi Liam,

I've taken the liberty to process your feedback in separate issues. You can find your debounce request here #17 and your sort column feedback here #18.

Regarding Aurelia. Yeah I did include the aurelia twitter account in my beta release tweet. Rob Eisenberg retweeted my tweet with his personal account, Durandal and AureliaFramework account. That got me a bit of traffic yes, but haven't seen anything about my plugin in any newsletter. Would love that though 😄 . I am glad you like it! I am still working ironing some bugs out so it should become even better!

@MrBliz Thanks for the suggestion! The samples have been cleaned up.