Skip to content

Commit 49ea361

Browse files
committed
Grid: Allow columns option to specify a label, use existing text when reading from markup.
1 parent cbd13be commit 49ea361

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

grid-spf/autocomplete.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
// TODO the table is empty, so let's create it from scratch here
5656
var grid = $( "table" ).grid({
5757
source: cities.result,
58-
columns: [ "name", "adminName1", "adminCode1", "fclName", "adminName2", "population", "countryName" ]
58+
columns: [ {property: "name", label: "Name"}, {property: "adminName1", label: "Area"}, {property:"adminName2", label:"Province"}, {property:"population", label:"Population"}, {property:"countryName", label:"Country"} ]
5959
});
6060
});
6161
</script>

grid-spf/grid.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
});
8787

8888
$( "#developers-local" ).grid({
89-
columns: [ "firstName", "lastName", "country" ],
9089
source: developers.result,
9190
select: function( event, ui ) {
9291
console.log( "Selected " + ui.item.firstName );

grid-spf/grid.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ $.widget( "ui.grid", {
104104
var head = this.element.find("thead");
105105
if ( !head.find( "th" ).length ) {
106106
$.each( this.options.columns, function( index, column ) {
107-
$( "<th>" ).text(column.property).appendTo(head);
107+
$( "<th>" ).text(column.label || column.property).appendTo(head);
108108
});
109109
}
110110
return;
@@ -115,10 +115,12 @@ $.widget( "ui.grid", {
115115
var property = th.data( "property" );
116116
if ( !property ) {
117117
// generate property name if missing
118+
// replaces whitespace and non-alphanumerics with underscore
118119
property = th.text().toLowerCase().replace(/\s|[^a-z0-9]/g, "_");
119120
}
120121
var result = {
121-
property: property
122+
property: property,
123+
label: th.text()
122124
};
123125
$.each( dataFields, function(index, dataField) {
124126
result[dataField] = th.data( dataField );

0 commit comments

Comments
 (0)