<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ar">
	<id>https://3rabica.org/index.php?action=history&amp;feed=atom&amp;title=%D9%88%D8%AD%D8%AF%D8%A9%3AAutosortTable</id>
	<title>وحدة:AutosortTable - تاريخ المراجعة</title>
	<link rel="self" type="application/atom+xml" href="https://3rabica.org/index.php?action=history&amp;feed=atom&amp;title=%D9%88%D8%AD%D8%AF%D8%A9%3AAutosortTable"/>
	<link rel="alternate" type="text/html" href="https://3rabica.org/index.php?title=%D9%88%D8%AD%D8%AF%D8%A9:AutosortTable&amp;action=history"/>
	<updated>2026-06-06T17:18:42Z</updated>
	<subtitle>تاريخ التعديل لهذه الصفحة في الويكي</subtitle>
	<generator>MediaWiki 1.43.7</generator>
	<entry>
		<id>https://3rabica.org/index.php?title=%D9%88%D8%AD%D8%AF%D8%A9:AutosortTable&amp;diff=1623&amp;oldid=prev</id>
		<title>عبد العزيز: أنشأ الصفحة ب&#039;--[[ AutosortTable: Creates a table which is automatically sorted   Usage: (Remove the hidden comments before use)   {{#invoke: AutosortTable|create   | class = wikitabl...&#039;</title>
		<link rel="alternate" type="text/html" href="https://3rabica.org/index.php?title=%D9%88%D8%AD%D8%AF%D8%A9:AutosortTable&amp;diff=1623&amp;oldid=prev"/>
		<updated>2019-05-28T22:33:28Z</updated>

		<summary type="html">&lt;p&gt;أنشأ الصفحة ب&amp;#039;--[[ AutosortTable: Creates a table which is automatically sorted   Usage: (Remove the hidden comments before use)   {{#invoke: AutosortTable|create   | class = wikitabl...&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;صفحة جديدة&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[&lt;br /&gt;
AutosortTable: Creates a table which is automatically sorted&lt;br /&gt;
 &lt;br /&gt;
Usage: (Remove the hidden comments before use)&lt;br /&gt;
 &lt;br /&gt;
{{#invoke: AutosortTable|create&lt;br /&gt;
 &lt;br /&gt;
| class = wikitable                            &amp;lt;!-- Class for the entire table --&amp;gt;&lt;br /&gt;
| style = width: 50%;                          &amp;lt;!-- CSS for the entire table --&amp;gt;&lt;br /&gt;
| sep = --                                     &amp;lt;!-- Separator string used to separate cells --&amp;gt;&lt;br /&gt;
| order = 2, 1                                 &amp;lt;!-- Order for sorting preference, takes a coma-separated list of column numbers --&amp;gt;&lt;br /&gt;
| nsort = 2                                    &amp;lt;!-- Columns which use numeric sorting. Takes a coma-separated list of column numbers --&amp;gt;&lt;br /&gt;
| header =  -- Name -- Age                     &amp;lt;!-- Table header --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
| -- Bob -- 20                                 &amp;lt;!-- Row 1 --&amp;gt;&lt;br /&gt;
| -- Peter -- 35                               &amp;lt;!-- Row 2 --&amp;gt;&lt;br /&gt;
| -- John -- 35                                &amp;lt;!-- Row 3 --&amp;gt;&lt;br /&gt;
| -- James -- 50                               &amp;lt;!-- Row 4 --&amp;gt;&lt;br /&gt;
| background-color: #FFDDDD -- Henry -- 45     &amp;lt;!-- Row 5, with CSS --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
}}&lt;br /&gt;
]]&lt;br /&gt;
 &lt;br /&gt;
local _module = {}&lt;br /&gt;
 &lt;br /&gt;
_module.create = function(frame)&lt;br /&gt;
 &lt;br /&gt;
    local args = frame.args&lt;br /&gt;
 &lt;br /&gt;
    -- Named parameters&lt;br /&gt;
 &lt;br /&gt;
    local class = args.class&lt;br /&gt;
    local style = args.style&lt;br /&gt;
    local sep = args.separator&lt;br /&gt;
    local order = args.order&lt;br /&gt;
    local desc = args.descending or &amp;quot;&amp;quot;&lt;br /&gt;
    local nsort = args.numeric or &amp;quot;&amp;quot;&lt;br /&gt;
    local hidden = args.hidden or &amp;quot;&amp;quot;&lt;br /&gt;
    local header = args.header&lt;br /&gt;
    local footer = args.footer&lt;br /&gt;
    local colstyle = args.colstyle&lt;br /&gt;
 &lt;br /&gt;
    -- Frequently-used functions&lt;br /&gt;
 &lt;br /&gt;
    local strIndexOf = mw.ustring.find&lt;br /&gt;
    local strSplit = mw.text.split&lt;br /&gt;
    local strSub = mw.ustring.sub&lt;br /&gt;
    local strTrim = mw.text.trim&lt;br /&gt;
 &lt;br /&gt;
    local seplen = #sep&lt;br /&gt;
    local nsortLookup, descLookup, hiddenLookup = {}, {}, {}&lt;br /&gt;
 &lt;br /&gt;
    -- Create the table&lt;br /&gt;
 &lt;br /&gt;
    local html = mw.html.create()&lt;br /&gt;
    local htable = html:tag(&amp;#039;table&amp;#039;)&lt;br /&gt;
    if class then htable:attr(&amp;#039;class&amp;#039;, class) end&lt;br /&gt;
    if style then htable:attr(&amp;#039;style&amp;#039;, style) end&lt;br /&gt;
 &lt;br /&gt;
    -- Parses a row string. The key paremter is used to assign a unique key to the result so that equal rows do not cause sort errors.&lt;br /&gt;
    local parse = function(s, key)&lt;br /&gt;
        local css&lt;br /&gt;
        local firstSep = strIndexOf(s, sep, 1, true)&lt;br /&gt;
        if firstSep == 1 then  -- no CSS&lt;br /&gt;
            css = nil&lt;br /&gt;
            s = strSub(s, seplen + 1, -1)&lt;br /&gt;
        else   -- CSS before first separator&lt;br /&gt;
            css = strSub(s, 1, firstSep - 1)&lt;br /&gt;
            s = strSub(s, firstSep + seplen, -1)&lt;br /&gt;
        end &lt;br /&gt;
 &lt;br /&gt;
        return { key = key, css = css, data = strSplit(s, sep, true) }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    --[[&lt;br /&gt;
        Writes a row to the table.&lt;br /&gt;
        css: CSS to apply to the row.&lt;br /&gt;
        data: The data (cells) of the row&lt;br /&gt;
        _type: Can be &amp;#039;header&amp;#039;, &amp;#039;footer&amp;#039; or nil.&lt;br /&gt;
    ]]&lt;br /&gt;
    local writeHtml = function(css, data, _type)&lt;br /&gt;
        local row = htable:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
        if css then row:attr(&amp;#039;style&amp;#039;, strTrim(css)) end&lt;br /&gt;
 &lt;br /&gt;
        for i, v in ipairs(data) do&lt;br /&gt;
            if not hiddenLookup[i] then&lt;br /&gt;
                local cell&lt;br /&gt;
                if _type == &amp;#039;header&amp;#039; then&lt;br /&gt;
                    -- Header: use the &amp;#039;th&amp;#039; tag with scope=&amp;quot;col&amp;quot;&lt;br /&gt;
                    cell = row:tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
                    cell:attr(&amp;#039;scope&amp;#039;, &amp;#039;col&amp;#039;)&lt;br /&gt;
                elseif _type == &amp;#039;footer&amp;#039; then&lt;br /&gt;
                    -- Footer: Mark as &amp;#039;sortbottom&amp;#039; so that it does not sort whe the table is made user-sortable&lt;br /&gt;
                    -- with the &amp;#039;wikitable sortable&amp;#039; class&lt;br /&gt;
                    cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
                    cell:class(&amp;#039;sortbottom&amp;#039;)&lt;br /&gt;
                else&lt;br /&gt;
                    -- Ordinary cell&lt;br /&gt;
                    cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
                    local cellCss = colstyle and colstyle[i]&lt;br /&gt;
                    if cellCss then cell:attr(&amp;#039;style&amp;#039;, strTrim(cellCss)) end   -- Apply the column styling, if necessary&lt;br /&gt;
                end&lt;br /&gt;
                cell:wikitext(strTrim(v))&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
 &lt;br /&gt;
        return row&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    -- Parse the column styles&lt;br /&gt;
    if colstyle then colstyle = parse(colstyle, -1).data end&lt;br /&gt;
 &lt;br /&gt;
    -- Write the header first&lt;br /&gt;
    if header then&lt;br /&gt;
        local headerData = parse(header)&lt;br /&gt;
        writeHtml(headerData.css, headerData.data, &amp;#039;header&amp;#039;)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    -- Parse the data&lt;br /&gt;
    local data = {}&lt;br /&gt;
    for i, v in ipairs(frame.args) do data[i] = parse(v, i) end&lt;br /&gt;
 &lt;br /&gt;
    order = strSplit(order, &amp;#039;%s*,%s*&amp;#039;)&lt;br /&gt;
    nsort = strSplit(nsort, &amp;#039;%s*,%s*&amp;#039;)&lt;br /&gt;
    desc = strSplit(desc, &amp;#039;%s*,%s*&amp;#039;)&lt;br /&gt;
    hidden = strSplit(hidden, &amp;#039;%s*,%s*&amp;#039;)&lt;br /&gt;
 &lt;br /&gt;
    for i, v in ipairs(order) do order[i] = tonumber(v) end&lt;br /&gt;
    for i, v in ipairs(nsort) do nsortLookup[tonumber(v) or -1] = true end&lt;br /&gt;
    for i, v in ipairs(desc) do descLookup[tonumber(v) or -1] = true end&lt;br /&gt;
    for i, v in ipairs(hidden) do hiddenLookup[tonumber(v) or -1] = true end&lt;br /&gt;
 &lt;br /&gt;
    --Sorting comparator function.&lt;br /&gt;
    local sortFunc = function(a, b)&lt;br /&gt;
        local ad, bd = a.data, b.data&lt;br /&gt;
        for i = 1, #order do&lt;br /&gt;
            local index = order[i]&lt;br /&gt;
            local ai, bi = ad[index], bd[index]&lt;br /&gt;
            if nsortLookup[index] then&lt;br /&gt;
                -- Numeric sort. Find the first occurence of a number an use it. Decimal points are allowed. Scientific notation not supported.&lt;br /&gt;
                ai = tonumber( (ai:find(&amp;#039;.&amp;#039;, 1, true) and ai:match(&amp;#039;[+-]?%d*%.%d+&amp;#039;) or ai:match(&amp;#039;[+-]?%d+&amp;#039;)) or 0 )&lt;br /&gt;
                bi = tonumber( (bi:find(&amp;#039;.&amp;#039;, 1, true) and bi:match(&amp;#039;[+-]?%d*%.%d+&amp;#039;) or bi:match(&amp;#039;[+-]?%d+&amp;#039;)) or 0 )&lt;br /&gt;
            end&lt;br /&gt;
            if ai ~= bi then&lt;br /&gt;
                if descLookup[index] then return ai &amp;gt; bi else return ai &amp;lt; bi end&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
        return a.key &amp;lt; b.key&lt;br /&gt;
    end&lt;br /&gt;
    table.sort(data, sortFunc)&lt;br /&gt;
 &lt;br /&gt;
    -- Write the sorted data to the HTML output&lt;br /&gt;
    for i, v in ipairs(data) do writeHtml(v.css, v.data, nil) end&lt;br /&gt;
 &lt;br /&gt;
    -- Write the footer&lt;br /&gt;
    if footer then&lt;br /&gt;
        local footerData = parse(footer)&lt;br /&gt;
        writeHtml(footerData.css, footerData.data, &amp;#039;footer&amp;#039;)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    return tostring(html)&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
return _module&lt;/div&gt;</summary>
		<author><name>عبد العزيز</name></author>
	</entry>
</feed>