datatable, realized in the columns field, a hyperlink with a laravel path that passes a parameter

datatable, realized in the columns field, a hyperlink with a laravel path that passes a parameter

Frank0908Frank0908 Posts: 1Questions: 1Answers: 0

Good morning, I have a problem that I have been looking for a solution, I am passing a dataTable that is initialized by the client view, with the ajax method to load everything on the server side, so far it was easy, I managed to recover all the data which I need, but in the dataTable that didn't use ajax, I had a hyperlink that passed a parameter to enter another view, but now when I create the hyperlink it works fine, but the parameter takes me as a string instead of retrieving the value that I give it I want to pass.

I pass the code of how I perform the hyperlink creation process in columns:

$(document).ready(function(){
            $('#usuarios').DataTable(
            {
                // processing: true,
                serverSide:true,
                responsive: true,
                ajax: "{{route('dataTable', $procesoElegido)}}",
                dataType: 'json',
            "columns":[
                {data: 'proceso.user_proceso.Matricula'},
                // {data: 'proceso.user_proceso.alumno_perfil_user.Nombre'},
                {
                data: null,
                render: function (data, type, row) 
                    {


            return '<a href="{{ route('progresoDocumentacion','$id=data.proceso.IdProceso')}}">' + data.proceso.user_proceso.alumno_perfil_user.Nombre + ' ' + data.proceso.user_proceso.alumno_perfil_user.APP + ' ' + data.proceso.user_proceso.alumno_perfil_user.APM + '</a>';

                    }
                }, 

In the second data column it gives me the error, specifically in the href, when I try to pass the variable, I have tried it in several ways, at first I thought that I am using the single and double quotes wrong, but still I keep getting error, when I enter to the hyperlink, the URL comes out as follows:

"http:// 127.0.0.1: 8000/ user process/%24id=data.process.ProcessId"

When in reality I should be passing a numeric value that I try to pass through data.process.IdProceso.

Well, maybe it is something easier to do and due to ignorance I have not observed or detected it, I hope someone can help me, thanks.

**:

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin
    Answer ✓

    {{ route('progresoDocumentacion','$id=data.proceso.IdProceso')}}

    That is a server-side template construct.

    Do you have the id in the row's data object? You need to create the URL on the client-side with the id for the row in question - perhaps something like:

    return '<a href="{{ route('progresoDocumentacion')}}/'+ data.wheverTheIdIs +">' + ... + '</a>';
    

    I don't know exactly how the route method will work like that, but assuming it would give the base URL that you can then just add the id onto, then that's how it could be done.

    The other option is to resolve the route in the server-side script, so it is already in the data that the table is loading and you just show that.

    Allan

Sign In or Register to comment.