Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fieldOrder option to enable the user to control the fields' order #2183

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions jquery.jtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ THE SOFTWARE.
//Options
actions: {},
fields: {},
fieldOrder: [],
animationsEnabled: true,
defaultDateFormat: 'yy-mm-dd',
dialogShowEffect: 'fade',
Expand Down Expand Up @@ -199,21 +200,31 @@ THE SOFTWARE.
_createFieldAndColumnList: function () {
var self = this;

$.each(self.options.fields, function (name, props) {

//Add field to the field list
self._fieldList.push(name);

//Check if this field is the key field
if (props.key == true) {
self._keyField = name;
//fill columnList according to order
$.each(self.options.fieldOrder,
function (index, value) {
if (value in self.options.fields) {
self._columnList.push(value);
}
}
);

//fill rest of columns, if not part of fieldOrder already
$.each(self.options.fields,
function (name, props)
{
self._fieldList.push(name);
if (props.key == true) {
self._keyField = name;
}

//Add field to column list if it is shown in the table
if (props.list != false && props.type != 'hidden') {
self._columnList.push(name);
if (props.list != false && props.type != 'hidden') {
if ($.inArray(name, self._columnList) == -1) {
self._columnList.push(name);
}
}
}
});
);
},

/* Creates the main container div.
Expand Down