Table header filtering via another column

Table header filtering via another column

Andrew_ghoshAndrew_ghosh Posts: 3Questions: 1Answers: 0
edited March 2023 in Free community support

I try to filter a header section of data table, If we select a state in city column show the there own city's only

 GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'atmcode:ntext',
            'atmname:ntext',
            [
                'label' => 'State',
                'attribute' => 'state',
                'value' => 'state',
                'filter' => Html::dropDownList('ClubSearch[state]', $searchModel->state, ArrayHelper::map(ClubQuery::getStates(), 'state', 'state'), ['prompt' => '-- Select State --', 'class' => 'form-control', 'id' => 'stateID']),
            ],
            [
                'label' => 'City',
                'attribute' => 'city',
                'value' => 'city',
                'filter' => Html::dropDownList('ClubSearch[city]', $searchModel->city, ArrayHelper::map(ClubQuery::getCities(), 'city', 'city'), ['prompt' => '-- Select City --', 'class' => 'form-control', 'id' => 'cityID']),
            ],  
        ],
    ]); 

and i try filtering via ajax that code is

 $( document ).ready(function() {     
    $("#stateID").on('change', function(e){
        var state = $(this).val()
        $('#cityID').empty();
        $.ajax({
            'method': 'GET',
            'url': baseurl + 'cms/club/city-from-ajax?id=' + state,
            success: function (data) {
                if (data === "") {
                } else {
                    $("#cityID").html(data);
                }
            }
        });
    })
});

but no response from Ajax request , how we do this filtering , thanks in advance

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Answers

  • kthorngrenkthorngren Posts: 20,331Questions: 26Answers: 4,774
    edited March 2023

    I don't see where Datatables is involved with this code. There is nothing obvious from the code snippets that looks to be a problem. Please post a link to your page or a test case replicating the issues we can understand your code flow and help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • Andrew_ghoshAndrew_ghosh Posts: 3Questions: 1Answers: 0

    no response from Ajax request it show blank but same ajax code will work in another page or any another way filter city via state

  • Andrew_ghoshAndrew_ghosh Posts: 3Questions: 1Answers: 0

    i try to change the value of city from ajax request

  • kthorngrenkthorngren Posts: 20,331Questions: 26Answers: 4,774
    edited March 2023

    no response from Ajax request it show blank

    Then you will need to debug your server code to find out why the response is empty.

    i try to change the value of city from ajax request

    Not sure what city is. Again, without seeing what you have is difficult to offer suggestions.
    Please post a link to a test case replicating the issue.

    Kevin

Sign In or Register to comment.