edge-blade / vue-materials

Vue 2.0 and Materialize.css Components
MIT License
2 stars 0 forks source link

Improve Table Headers Capitalize #14

Closed edge-blade closed 7 years ago

edge-blade commented 7 years ago

Currently the table-header renders with each property capitalized. The system should be slightly improved to create multiple words and create spaces on typical variable breaks.

e.g. CreateDate, create_date, create-date should all be converted to Create Date.

edge-blade commented 7 years ago

The following filter appears to work, but I may consider changing the columns parameter to accept an object instead taking { columnName:String, displayText: String }

convertColumnToTitle(str) {
    return str.replace(/[_-]/g, ' ')
        .replace(/([A-Z][a-z])/g, 
            function(match) { 
                if(match == '_' || match == '-') 
                    return ` `;
                return ` ${match}`;
            })
                .replace(/\w\S*/g, 
            function(txt) {
                return txt[0].toUpperCase() + txt.slice(1).toLowerCase();
            }
        );
}
edge-blade commented 7 years ago

Based on other table libraries it makes sense to allow custom header text so users have the option to set table headers to blank or different than the data property.