question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New column created from Object datatype

See original GitHub issue

Hello. This will be sound more like question than issue. So sorry in advance for posting this here How I able to create new column with value from Object ? Code of my setting and data below for more clearly understanding private settings = {

columns: {
      firstName: {
        title: 'First name',
        type: 'text'
      },
      lastName: {
        title: 'Last name',
        type: 'text'
      },
      userType: {  
        // This is correct way only when there is string in response from API named - userType
        // But when I'm trying to type something like - userType.value i get an error 
        title: 'User type',
        type: 'text'
      },
}

data from API:

.......
    {
      firstName: 'Jacob',
      lastName: '',
      middleName: '',
      userType: {value: 'superAdmin', display: 'Super Administrator'},
      login: '',
      password: '',
      phoneNumber: '066-233-77-34',
      city: 'Roma',
      address: 'someStreet',
      salary: '0',
    },
......

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
SantaUAcommented, Sep 15, 2017

@yadoble sure

private settings = {
    hideHeader: true,
    columns: {
      EntryDate: {
        title: 'Date',
        type: 'text',
        valuePrepareFunction: (value) => {
          return this.transformDate(value);
        },
        filterFunction: (value, search) => {
          let match = this.transformDate(value).indexOf(search) > -1
          if (match || search === '') { return true; }
          else { return false; }
        }
      }
}

methods:

  transformDate(value) {
    let newValue;
    newValue = this.datePipe.transform(value, 'dd.MM.yyyy');
    return newValue;
  }

Here is are a few important things:

  • valuePrepareFunction() change value for for view on html
  • filterFunction() for working filter after value was changed Why ? because ngSmartTable filter will sort column by value from your js code, not for view data Exp: if you will have data by ID and change view to name be ID(ID: 1 will be changed to NY) filter will working by ID not the view data if you won’t use the custom filter func
1reaction
SantaUAcommented, Mar 29, 2017

@KostyaDanovsky The night brings counsel ☺️ I got an idea invoke myCustomFunc in valuePrepareFunction. By myCustomFunc I parse value and return what should be

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding a new column with specific dtype in pandas
Obviously, you don't have to do this, but you can. df.drop('BP', 1).join( df['BP'].str.split('/', expand=True) .set_axis(['BPS', 'BPD'], ...
Read more >
Change Data Type for one or more columns in Pandas ...
Change column type into string object using DataFrame.astype(). DataFrame.astype() method is used to cast pandas object to a specified dtype.
Read more >
How To Add New Column to Pandas DataFrame
The method will return a new DataFrame object (a copy) containing all the original columns in addition to new ones:
Read more >
Add Column To Dataframe Pandas - Data Independent
The easiest way to create a new column is to simply write one out! Then assign either a scalar (single value) or a...
Read more >
Different Ways to Change Data Type in pandas
Use DataFrame.infer_objects() method to automatically convert object columns to a type of data it holding. It checks the data of each object column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found