javascriptgodatatables

How to use JQuery Datatable with Golang?


I am using JQuery Datatable to list the details in my Database. I wrote my server side in Golang. I have my database values stored in a map called dBdetails now I want to display the contents of this map using Datables. How can I do?


Solution

  • Just convert Map into a Slice and use it in JQuery.

    dataValue := reflect.ValueOf(dBdetails)
    var valueSlice []string
    for key, value := range dataValue.MapKeys() {
        keySlice = append(keySlice, key)
        valueSlice = append(valueSlice, value)
    }
    
    log.Println(keySlice, valueSlice)
    

    The above code will convert map into slice.