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

select field issue with String ID #2

Closed
geemang2000 opened this issue Jan 15, 2015 · 1 comment
Closed

select field issue with String ID #2

geemang2000 opened this issue Jan 15, 2015 · 1 comment
Labels

Comments

@geemang2000
Copy link

I'm having an issue with using a String for the valueField in a select. When I select a new item from the select the cell goes blank.

    $("#jsGrid").jsGrid({
        editing: true,
        data: db.apps,
        fields: [
    {name: "source", title:"Source", type: "select", items: db.sources, valueField: "Id", textField: "Name"}
    ...
    db.sources = [
        { Name: "Label1", Id: "LABEL1" },
        { Name: "Label2", Id: "LABEL2" }
    ];

See: http://jsbin.com/repexoyuqi/ (click a row, change the select value, click the first button on the control cell)

@tabalinas tabalinas added the bug label Jan 15, 2015
@tabalinas
Copy link
Owner

Yes, current SelectField implementation inherits NumberField and parses selected value to number. Of course, it should work for strings too.
For now there is a workaround.
Redefine editValue (filterValue and insertValue if filtering and inserting is needed) to avoid parsing.
(link to field config http://js-grid.com/docs/#fields)

{ name: "source", title:"Source", type: "select", 
  items: db.sources, valueField: "Id", textField: "Name"
  editValue : function() { return this.editControl.val(); }, // for editing
  filterValue : function() { return this.filterControl.val(); }, // for filter
  insertValue : function() { return this.insertControl.val(); } // for insert
} 

You also could define a new field to avoid grid config cluttering. Just register a new field inheriting from jsGrid.SelectField with following code:

function TextSelectField(config) {
    jsGrid.SelectField.call(this, config);
}

TextSelectField.prototype = new jsGrid.SelectField({

    sorter: "string",

    filterValue: function() {
        return this.filterControl.val();
    },

    insertValue: function() {
        return this.insertControl.val();
    },

    editValue: function() {
        return this.editControl.val();
    }
});

jsGrid.fields.textSelect = TextSelectField;

Now you can use this field just like before, but specify type="textSelect"instead of type="select"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants