SlickGrid Columns - Difference between id and field
Asked Answered
R

1

10

A simple question i cant workout. In a column definition whats the difference between the field property and the id property...Fx..

columns.push({ id: "officeId", name: "Office Id", field: "officeId", width: 40 });

When would they be different/why two?

Thanks? Tim

Roderic answered 22/9, 2011 at 13:17 Comment(1)
I think i figured this out. Seems like the id is the id to reference the column while the field is the data field in the dataset.Roderic
A
7

The id is just a unique identifier for the column. You can set it to anything you want. It's only use is to provide an identifier when you want to refer to your columns from code.

The field specifies how the column binds to the underlying data. Suppose your data looks like this:

data = [ 
         { firstName: "John", lastName: "Smith" },
         { firstName: "Fred", lastName: "Jones" }
       ];

When you define the column you can tell it which value you want to display from your data array.

columns.push({ id: "anythingyoulike", name: "Surname", field: "lastName", width: 40 });
Adelia answered 19/10, 2011 at 9:49 Comment(1)
Yes. In other words, id allows you to define two columns with the same name, which will handle equally named data.Collective

© 2022 - 2024 — McMap. All rights reserved.