Search code examples
visual-studio-lightswitchlightswitch-2013

sorting columns with MS lightswitch


I'm having some trouble with a lightswitch application of mine. When I click on the sorting arrow next to any of the columns in a table, it sorts the adjacent column, instead of the column for which I've clicked the sorting arrow? Has anyone else encountered this?enter image description here


Solution

  • Having investigated a similar issue earlier today, I suspect you've encountered a small flaw in Microsoft's LightSwitch library.

    This flaw appears if your table includes any columns with their visibility set to false and results in the column sorting being offset by the number of hidden columns preceding the clicked column.

    If this is the case, you can either resolve it by removing the hidden columns or, as Microsoft provide the source code for the LightSwitch library, you could revise the library to correct the flaw.

    If you'd like to implement this correction, you'll need to reference the un-minified version of the LightSwitch library by making the following change in your HTML client's default.htm file (to remove the .min from the end of the library script reference):

    <!--<script type="text/javascript" src="Scripts/msls-?.?.?.min.js"></script>-->
    <script type="text/javascript" src="Scripts/msls-?.?.?.js"></script>
    

    The question marks in the line above will relate to the version of LightSwitch you're using.

    You'll then need to locate the sortTableByColumn function in the Scripts/msls-?.?.?.js file and make the following revision to its code:

        //var header = columnContentItems[cellIndex];
        var header = columnContentItems.filter(function (item) {
            return item.isVisible;
        })[cellIndex];
    

    By applying a filter to the columnContentItems array, this change ensures only visible columns are considered when accessing the required element identified by the cellIndex parameter.