Column data is a function, server side gets "function" as column name

Column data is a function, server side gets "function" as column name

nickmcleannickmclean Posts: 5Questions: 1Answers: 0

I have a column with a data value based on a function. Something like this,

data: (row, type, set, meta) => {
   return '1';
}

I receive the data request server-side but the column definition contains Text: 'function'.

I understand why I'm getting this, which is because I haven't specified a field name, I've given it a function. The field name would normally be returned by the data field,

data: 'myDataFieldName',

The question is, is there another way to specify the field name that would make it return the correct field name instead of the word 'function'?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    columns.data can be a function, see here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • nickmcleannickmclean Posts: 5Questions: 1Answers: 0
    edited September 2021

    Hi Colin, yeah, I have it as a function, but when the data is coming from server-side, and you try to order by the column that has the data:function defined, it errors saying field name is "function".
    Unfortunately, this is an intranet site in pre-production so I can't provide a link, and because it requires a server-side feed, I can't update your example :(

  • montoyammontoyam Posts: 568Questions: 136Answers: 5
    edited September 2021

    I may be misunderstanding your question, but do you mean like this, using the 'title' parameter?

    { data: "Departments.DepartmentName", title: "Distribute to Dept Name" },
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Sorry, I'm still not following. This example here has serverSide, and is using a function. Could you modify that to demonstrate the issue, please,

    Colin

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited September 2021

    I think the question is around the request parameters, specifically this:

    columns[5][data]: function
    columns[5][name]: 
    columns[5][searchable]: true
    columns[5][orderable]: true
    columns[5][search][value]: 
    columns[5][search][regex]: false
    

    Where data is function.

    you try to order by the column that has the data:function defined, it errors saying field name is "function".

    is there another way to specify the field name that would make it return the correct field name instead of the word 'function'?

    Maybe you can use columns.data with the desired field name and use columns.render to display what you want. Another option is to use columns.orderable to disable ordering of that column.

    What do you want the server script to do with that column when you use columns.data as a function.

    Kevin

  • nickmcleannickmclean Posts: 5Questions: 1Answers: 0
    edited September 2021

    Server-side needs that column name to build the SQL order by clause. What field from the request do you use server-side to do the ordering?

    Server-side, I'm getting this in the request payload when I order by that column,

        order: [{
            "column": 12,
            "dir": "desc"
        }]
    

    And column 12 in the column data is,

        {
            data: "function",
            name: "GP £",
            searchable: true,
            orderable: true,
            search: {
                value: "",
                regex: false
            }
        }
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    The client specifies order in the request. The protocol is discussed here. Also see examples here.

    Cheers,

    Colin

  • nickmcleannickmclean Posts: 5Questions: 1Answers: 0

    So the intention is to order by column index and not by column name?

    order: [{
        "column": 12,
        "dir": "desc"
    }]
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Yep, that's correct - this thread discusses using names,

    Colin

  • nickmcleannickmclean Posts: 5Questions: 1Answers: 0

    Thanks for your help, colin. I have a working solution now :)

Sign In or Register to comment.